{"url":"https://api.github.com/repos/llvm/llvm-project/issues/92597","repository_url":"https://api.github.com/repos/llvm/llvm-project","labels_url":"https://api.github.com/repos/llvm/llvm-project/issues/92597/labels{/name}","comments_url":"https://api.github.com/repos/llvm/llvm-project/issues/92597/comments","events_url":"https://api.github.com/repos/llvm/llvm-project/issues/92597/events","html_url":"https://github.com/llvm/llvm-project/pull/92597","id":2303543428,"node_id":"PR_kwDOBITxeM5v1dgL","number":92597,"title":"[Clang][Sema] Diagnose current instantiation used as an incomplete base class","user":{"login":"sdkrystian","id":16629302,"node_id":"MDQ6VXNlcjE2NjI5MzAy","avatar_url":"https://avatars.githubusercontent.com/u/16629302?v=4","gravatar_id":"","url":"https://api.github.com/users/sdkrystian","html_url":"https://github.com/sdkrystian","followers_url":"https://api.github.com/users/sdkrystian/followers","following_url":"https://api.github.com/users/sdkrystian/following{/other_user}","gists_url":"https://api.github.com/users/sdkrystian/gists{/gist_id}","starred_url":"https://api.github.com/users/sdkrystian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdkrystian/subscriptions","organizations_url":"https://api.github.com/users/sdkrystian/orgs","repos_url":"https://api.github.com/users/sdkrystian/repos","events_url":"https://api.github.com/users/sdkrystian/events{/privacy}","received_events_url":"https://api.github.com/users/sdkrystian/received_events","type":"User","user_view_type":"public","site_admin":false},"labels":[{"id":1958965060,"node_id":"MDU6TGFiZWwxOTU4OTY1MDYw","url":"https://api.github.com/repos/llvm/llvm-project/labels/clang","name":"clang","color":"79b5d1","default":false,"description":"Clang issues not falling into any other category"},{"id":1958965546,"node_id":"MDU6TGFiZWwxOTU4OTY1NTQ2","url":"https://api.github.com/repos/llvm/llvm-project/labels/clang-tools-extra","name":"clang-tools-extra","color":"79b5d1","default":false,"description":""},{"id":1958993196,"node_id":"MDU6TGFiZWwxOTU4OTkzMTk2","url":"https://api.github.com/repos/llvm/llvm-project/labels/clang-tidy","name":"clang-tidy","color":"79b5d1","default":false,"description":""},{"id":1958998266,"node_id":"MDU6TGFiZWwxOTU4OTk4MjY2","url":"https://api.github.com/repos/llvm/llvm-project/labels/clang:frontend","name":"clang:frontend","color":"3b12ce","default":false,"description":"Language frontend issues, e.g. anything involving \"Sema\""}],"state":"closed","locked":false,"assignees":[],"milestone":null,"comments":1,"created_at":"2024-05-17T20:36:14Z","updated_at":"2024-05-20T18:45:00Z","closed_at":"2024-05-20T18:44:59Z","assignee":null,"author_association":"MEMBER","issue_field_values":[],"type":null,"active_lock_reason":null,"draft":false,"pull_request":{"url":"https://api.github.com/repos/llvm/llvm-project/pulls/92597","html_url":"https://github.com/llvm/llvm-project/pull/92597","diff_url":"https://github.com/llvm/llvm-project/pull/92597.diff","patch_url":"https://github.com/llvm/llvm-project/pull/92597.patch","merged_at":"2024-05-20T18:44:59Z"},"body":"Consider the following:\r\n```cpp\r\ntemplate<typename T>\r\nstruct A\r\n{\r\n    struct B : A { };\r\n};\r\n```\r\nAccording to [[class.derived.general] p2](http://eel.is/c++draft/class.derived.general#2):\r\n> [...] A _class-or-decltype_ shall denote a (possibly cv-qualified) class type that is not an incompletely defined class; any cv-qualifiers are ignored. [...]\r\n\r\nAlthough GCC and EDG rejects this, Clang accepts it. This is incorrect, as `A` is incomplete within its own definition (outside of a complete-class context). This patch correctly diagnoses instances where the current instantiation is used as a base class before it is complete.\r\n\r\nConversely, Clang erroneously rejects the following:\r\n```cpp\r\ntemplate<typename T>\r\nstruct A \r\n{\r\n    struct B;\r\n\r\n    struct C : B { };\r\n\r\n    struct B : C { }; // error: circular inheritance between 'C' and 'A::B'\r\n};\r\n```\r\nThough it may seem like no valid specialization of this template can be instantiated, an explicit specialization of either member classes for an implicit instantiated specialization of `A` would permit the definition of the other member class to be instantiated, e.g.:\r\n```cpp\r\ntemplate<>\r\nstruct A<int>::B { };\r\n\r\nA<int>::C c; // ok\r\n```\r\nSo this patch also does away with this error. This means that circular inheritance is diagnosed during instantiation of the definition as a consequence of requiring the base class types to be complete (matching the behavior of GCC and EDG).\r\n","closed_by":{"login":"sdkrystian","id":16629302,"node_id":"MDQ6VXNlcjE2NjI5MzAy","avatar_url":"https://avatars.githubusercontent.com/u/16629302?v=4","gravatar_id":"","url":"https://api.github.com/users/sdkrystian","html_url":"https://github.com/sdkrystian","followers_url":"https://api.github.com/users/sdkrystian/followers","following_url":"https://api.github.com/users/sdkrystian/following{/other_user}","gists_url":"https://api.github.com/users/sdkrystian/gists{/gist_id}","starred_url":"https://api.github.com/users/sdkrystian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdkrystian/subscriptions","organizations_url":"https://api.github.com/users/sdkrystian/orgs","repos_url":"https://api.github.com/users/sdkrystian/repos","events_url":"https://api.github.com/users/sdkrystian/events{/privacy}","received_events_url":"https://api.github.com/users/sdkrystian/received_events","type":"User","user_view_type":"public","site_admin":false},"reactions":{"url":"https://api.github.com/repos/llvm/llvm-project/issues/92597/reactions","total_count":0,"+1":0,"-1":0,"laugh":0,"hooray":0,"confused":0,"heart":0,"rocket":0,"eyes":0},"timeline_url":"https://api.github.com/repos/llvm/llvm-project/issues/92597/timeline","performed_via_github_app":null,"state_reason":null}