[all-commits] [llvm/llvm-project] 3a4863: [Clang][Sema] Diagnose friend declarations with en...
Krystian Stasiowski via All-commits
all-commits at lists.llvm.org
Tue Feb 13 11:26:08 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 3a48630a4b25d50abefd945742c247f17bd61156
https://github.com/llvm/llvm-project/commit/3a48630a4b25d50abefd945742c247f17bd61156
Author: Krystian Stasiowski <sdkrystian at gmail.com>
Date: 2024-02-13 (Tue, 13 Feb 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/include/clang/Sema/DeclSpec.h
M clang/include/clang/Sema/Sema.h
M clang/lib/Parse/ParseTentative.cpp
M clang/lib/Sema/DeclSpec.cpp
M clang/lib/Sema/SemaDecl.cpp
M clang/lib/Sema/SemaDeclCXX.cpp
M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
M clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
A clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p4.cpp
M clang/test/CXX/drs/dr16xx.cpp
M clang/test/CXX/drs/dr23xx.cpp
M clang/test/CXX/temp/temp.decls/temp.class/temp.mem.enum/p1.cpp
M clang/test/FixIt/fixit-c++11.cpp
M clang/test/Parser/cxx-decl.cpp
M clang/test/Parser/cxx0x-decl.cpp
M clang/test/SemaCXX/cxx98-compat.cpp
M clang/test/SemaCXX/enum-scoped.cpp
Log Message:
-----------
[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
};
```
More information about the All-commits
mailing list