diagnose C99 6.9.1p5, C arguments in definitions that are lacking
a name. This implements PR3208.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61127 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 8d6cdcb..57b967e 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -484,8 +484,9 @@
ObjCDeclQualifier getObjCDeclQualifier() const {
return ObjCDeclQualifier(objcDeclQualifier);
}
- void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
- { objcDeclQualifier = QTVal; }
+ void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
+ objcDeclQualifier = QTVal;
+ }
const Expr *getDefaultArg() const { return DefaultArg; }
Expr *getDefaultArg() { return DefaultArg; }
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index b379ab2..42ce6c7 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -720,6 +720,8 @@
"expected parameter declarator")
DIAG(err_bad_variable_name, ERROR,
"'%0' cannot be the name of a variable or data member")
+DIAG(err_parameter_name_omitted, ERROR,
+ "parameter name omitted")
DIAG(err_declarator_need_ident, ERROR,
"declarator requires an identifier")
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 424ce7f..6ef9ecd 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -720,6 +720,11 @@
Param->setInvalidDecl();
HasInvalidParm = true;
}
+
+ // C99 6.9.1p5: If the declarator includes a parameter type list, the
+ // declaration of each parameter shall include an identifier.
+ if (Param->getIdentifier() == 0 && !getLangOptions().CPlusPlus)
+ Diag(Param->getLocation(), diag::err_parameter_name_omitted);
}
return HasInvalidParm;
diff --git a/test/CodeGen/rdr-6140807-alias-references-forward.c b/test/CodeGen/rdr-6140807-alias-references-forward.c
index eff69ac..5fe15d1 100644
--- a/test/CodeGen/rdr-6140807-alias-references-forward.c
+++ b/test/CodeGen/rdr-6140807-alias-references-forward.c
@@ -10,5 +10,5 @@
return f(1.);
}
-int x(int) {
+int x(int a) {
}
diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c
index f77b570..78addb9 100644
--- a/test/Parser/recovery.c
+++ b/test/Parser/recovery.c
@@ -20,7 +20,7 @@
// rdar://6094870
-int test(int) {
+int test(int a) {
struct { int i; } x;
if (x.hello) // expected-error {{no member named 'hello'}}
diff --git a/test/Sema/c89.c b/test/Sema/c89.c
index 70949f0..b1780e9 100644
--- a/test/Sema/c89.c
+++ b/test/Sema/c89.c
@@ -44,7 +44,8 @@
void test8(int, x); /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
typedef int sometype;
-int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
+int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \
+ expected-error {{parameter name omitted}}*/
diff --git a/test/Sema/function.c b/test/Sema/function.c
index 7c67bba..f2aa8d9 100644
--- a/test/Sema/function.c
+++ b/test/Sema/function.c
@@ -29,3 +29,6 @@
void t10(){}
void t11(){t10(1);}
+// PR3208
+void t12(int) {} // expected-error{{parameter name omitted}}
+
diff --git a/test/Sema/redefinition.c b/test/Sema/redefinition.c
index 9ad77f6..5e79070 100644
--- a/test/Sema/redefinition.c
+++ b/test/Sema/redefinition.c
@@ -1,5 +1,5 @@
// RUN: clang %s -fsyntax-only -verify
-int f(int) { } // expected-note {{previous definition is here}}
+int f(int a) { } // expected-note {{previous definition is here}}
int f(int);
-int f(int) { } // expected-error {{redefinition of 'f'}}
+int f(int a) { } // expected-error {{redefinition of 'f'}}