[Clang] [Parser] Improve diagnostic for friend concept
(#105121)
Diagnose this early after parsing declaration specifiers; this allows us to issue a better diagnostic. This also checks for `concept friend` and concept declarations w/o a template-head because it’s easiest to do that at the same time. Fixes #45182.
This commit is contained in:
parent
d010ec6af8
commit
8b5f606612
@ -241,6 +241,8 @@ Improvements to Clang's diagnostics
|
||||
|
||||
- Don't emit duplicated dangling diagnostics. (#GH93386).
|
||||
|
||||
- Improved diagnostic when trying to befriend a concept. (#GH45182).
|
||||
|
||||
Improvements to Clang's time-trace
|
||||
----------------------------------
|
||||
|
||||
|
@ -974,6 +974,9 @@ def warn_cxx23_variadic_friends : Warning<
|
||||
"variadic 'friend' declarations are incompatible with C++ standards before C++2c">,
|
||||
DefaultIgnore, InGroup<CXXPre26Compat>;
|
||||
|
||||
def err_friend_concept : Error<
|
||||
"friend declaration cannot be a concept">;
|
||||
|
||||
// C++11 default member initialization
|
||||
def ext_nonstatic_member_init : ExtWarn<
|
||||
"default member initializer for non-static data member is a C++11 "
|
||||
|
@ -3139,6 +3139,19 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
|
||||
return Actions.BuildDeclaratorGroup(Decls);
|
||||
}
|
||||
|
||||
// Befriending a concept is invalid and would already fail if
|
||||
// we did nothing here, but this allows us to issue a more
|
||||
// helpful diagnostic.
|
||||
if (Tok.is(tok::kw_concept)) {
|
||||
Diag(Tok.getLocation(),
|
||||
DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
|
||||
? diag::err_friend_concept
|
||||
: diag::
|
||||
err_concept_decls_may_only_appear_in_global_namespace_scope);
|
||||
SkipUntil(tok::semi, tok::r_brace, StopBeforeMatch);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ParsingDeclarator DeclaratorInfo(*this, DS, DeclAttrs,
|
||||
DeclaratorContext::Member);
|
||||
if (TemplateInfo.TemplateParams)
|
||||
|
13
clang/test/Parser/friend-concept.cpp
Normal file
13
clang/test/Parser/friend-concept.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
|
||||
|
||||
template<class>
|
||||
concept fooable = true;
|
||||
|
||||
struct S {
|
||||
template<class> friend concept x = requires { requires true; }; // expected-error {{friend declaration cannot be a concept}}
|
||||
template<class> friend concept fooable; // expected-error {{friend declaration cannot be a concept}}
|
||||
template<class> concept friend fooable; // expected-error {{expected unqualified-id}}
|
||||
friend concept fooable; // expected-error {{friend declaration cannot be a concept}}
|
||||
concept friend fooable; // expected-error {{friend declaration cannot be a concept}}
|
||||
concept fooable; // expected-error {{concept declarations may only appear in global or namespace scope}}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user