forked from OSchip/llvm-project
Slightly improve the diagnostic when using a qualified function typedef to declare nonmember or static member functions.
llvm-svn: 108018
This commit is contained in:
parent
6bc772eec7
commit
3e39272fed
|
@ -2158,8 +2158,8 @@ def err_invalid_member_use_in_static_method : Error<
|
||||||
def err_invalid_qualified_function_type : Error<
|
def err_invalid_qualified_function_type : Error<
|
||||||
"type qualifier is not allowed on this function">;
|
"type qualifier is not allowed on this function">;
|
||||||
def err_invalid_qualified_typedef_function_type_use : Error<
|
def err_invalid_qualified_typedef_function_type_use : Error<
|
||||||
"a qualified function type cannot be used to declare a nonmember function "
|
"a qualified function type cannot be used to declare a "
|
||||||
"or a static member function">;
|
"%select{static member|nonmember}0 function">;
|
||||||
|
|
||||||
def err_invalid_non_static_member_use : Error<
|
def err_invalid_non_static_member_use : Error<
|
||||||
"invalid use of nonstatic data member %0">;
|
"invalid use of nonstatic data member %0">;
|
||||||
|
|
|
@ -1320,18 +1320,19 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
|
||||||
// for a nonstatic member function, the function type to which a pointer
|
// for a nonstatic member function, the function type to which a pointer
|
||||||
// to member refers, or the top-level function type of a function typedef
|
// to member refers, or the top-level function type of a function typedef
|
||||||
// declaration.
|
// declaration.
|
||||||
|
bool FreeFunction = (D.getContext() != Declarator::MemberContext &&
|
||||||
|
(!D.getCXXScopeSpec().isSet() ||
|
||||||
|
!computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)->isRecord()));
|
||||||
if (FnTy->getTypeQuals() != 0 &&
|
if (FnTy->getTypeQuals() != 0 &&
|
||||||
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
|
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
|
||||||
((D.getContext() != Declarator::MemberContext &&
|
(FreeFunction ||
|
||||||
(!D.getCXXScopeSpec().isSet() ||
|
|
||||||
!computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)
|
|
||||||
->isRecord())) ||
|
|
||||||
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) {
|
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) {
|
||||||
if (D.isFunctionDeclarator())
|
if (D.isFunctionDeclarator())
|
||||||
Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_function_type);
|
Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_function_type);
|
||||||
else
|
else
|
||||||
Diag(D.getIdentifierLoc(),
|
Diag(D.getIdentifierLoc(),
|
||||||
diag::err_invalid_qualified_typedef_function_type_use);
|
diag::err_invalid_qualified_typedef_function_type_use)
|
||||||
|
<< FreeFunction;
|
||||||
|
|
||||||
// Strip the cv-quals from the type.
|
// Strip the cv-quals from the type.
|
||||||
T = Context.getFunctionType(FnTy->getResultType(), FnTy->arg_type_begin(),
|
T = Context.getFunctionType(FnTy->getResultType(), FnTy->arg_type_begin(),
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
void f() const; // expected-error {{type qualifier is not allowed on this function}}
|
void f() const; // expected-error {{type qualifier is not allowed on this function}}
|
||||||
|
|
||||||
typedef void cfn() const;
|
typedef void cfn() const;
|
||||||
cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function or a static member function}}
|
cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function}}
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
void f() const;
|
void f() const;
|
||||||
cfn f2;
|
cfn f2;
|
||||||
static void f3() const; // expected-error {{type qualifier is not allowed on this function}}
|
static void f3() const; // expected-error {{type qualifier is not allowed on this function}}
|
||||||
static cfn f4; // expected-error {{a qualified function type cannot be used to declare a nonmember function or a static member function}}
|
static cfn f4; // expected-error {{a qualified function type cannot be used to declare a static member function}}
|
||||||
|
|
||||||
void m1() {
|
void m1() {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
|
Loading…
Reference in New Issue