зеркало из https://github.com/microsoft/clang.git
Provide an error when a non-identifier name (such as an operator) is used as a
parameter name. Fixes PR8012. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118138 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
40749ee585
Коммит
7533a5b65f
|
@ -95,6 +95,8 @@ def ext_anon_param_requires_type_specifier : Extension<
|
|||
"type specifier required for unnamed parameter, defaults to int">;
|
||||
def err_bad_variable_name : Error<
|
||||
"'%0' cannot be the name of a variable or data member">;
|
||||
def err_bad_parameter_name : Error<
|
||||
"'%0' cannot be the name of a parameter">;
|
||||
def err_parameter_name_omitted : Error<"parameter name omitted">;
|
||||
def warn_unused_parameter : Warning<"unused parameter %0">,
|
||||
InGroup<UnusedParameter>, DefaultIgnore;
|
||||
|
|
|
@ -4757,8 +4757,18 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
|
|||
<< Context.getTypeDeclType(OwnedDecl);
|
||||
}
|
||||
|
||||
// Ensure we have a valid name
|
||||
IdentifierInfo *II = 0;
|
||||
if (D.hasName()) {
|
||||
II = D.getIdentifier();
|
||||
if (!II) {
|
||||
Diag(D.getIdentifierLoc(), diag::err_bad_parameter_name)
|
||||
<< GetNameForDeclarator(D).getName().getAsString();
|
||||
D.setInvalidType(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for redeclaration of parameters, e.g. int foo(int x, int x);
|
||||
IdentifierInfo *II = D.getIdentifier();
|
||||
if (II) {
|
||||
LookupResult R(*this, II, D.getIdentifierLoc(), LookupOrdinaryName,
|
||||
ForRedeclaration);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
|
||||
|
||||
void foo (int operator+); // expected-error{{cannot be the name of a parameter}}
|
Загрузка…
Ссылка в новой задаче