-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Sema] Diagnose friend declarations with enum elaborated-type-…
…specifier in all language modes (#80171) According to [dcl.type.elab] p4: > If an _elaborated-type-specifier_ appears with the `friend` specifier as an entire _member-declaration_, the _member-declaration_ shall have one of the following forms: > `friend` _class-key_ _nested-name-specifier_(opt) _identifier_ `;` > `friend` _class-key_ _simple-template-id_ `;` > `friend` _class-key_ _nested-name-specifier_ `template`(opt) _simple-template-id_ `;` Notably absent from this list is the `enum` form of an _elaborated-type-specifier_ "`enum` _nested-name-specifier_(opt) _identifier_", which appears to be intentional per the resolution of CWG2363. Most major implementations accept these declarations, so the diagnostic is a pedantic warning across all C++ versions. In addition to the trivial cases previously diagnosed in C++98, we now diagnose cases where the _elaborated-type-specifier_ has a dependent _nested-name-specifier_: ``` template<typename T> struct A { enum class E; }; struct B { template<typename T> friend enum A<T>::E; // pedantic warning: elaborated enumeration type cannot be a friend }; template<typename T> struct C { friend enum T::E; // pedantic warning: elaborated enumeration type cannot be a friend }; ```
- Loading branch information
1 parent
1b65742
commit 3a48630
Showing
19 changed files
with
185 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p4.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: %clang_cc1 -verify %s -std=c++11 -pedantic-errors | ||
|
||
enum class E; | ||
|
||
template<typename T> | ||
struct A { | ||
enum class F; | ||
}; | ||
|
||
struct B { | ||
template<typename T> | ||
friend enum A<T>::F; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum' to befriend an enum}} | ||
|
||
// FIXME: Per [temp.expl.spec]p19, a friend declaration cannot be an explicit specialization | ||
template<> | ||
friend enum A<int>::F; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum' to befriend an enum}} | ||
|
||
enum class G; | ||
|
||
friend enum E; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum' to befriend an enum}} | ||
}; | ||
|
||
template<typename T> | ||
struct C { | ||
friend enum T::G; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum' to befriend an enum}} | ||
friend enum A<T>::G; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum' to befriend an enum}} | ||
}; | ||
|
||
struct D { | ||
friend enum B::G; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum' to befriend an enum}} | ||
friend enum class B::G; // expected-error {{elaborated enum specifier cannot be declared as a friend}} | ||
// expected-note@-1 {{remove 'enum class' to befriend an enum}} | ||
// expected-error@-2 {{reference to enumeration must use 'enum' not 'enum class'}} | ||
}; |
Oops, something went wrong.