aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-17 07:32:46 +0000
committerChris Lattner <sabre@nondot.org>2008-12-17 07:32:46 +0000
commit777f07b6cd595bb0922e05768e5703fbc92b5695 (patch)
tree89d18302ba4e12c34a7699f60fde175c4cfe3456
parentcc98eac383718899462b9b1361c46eea8dddfb2b (diff)
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
-rw-r--r--include/clang/AST/Decl.h5
-rw-r--r--include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--lib/Sema/SemaDecl.cpp5
-rw-r--r--test/CodeGen/rdr-6140807-alias-references-forward.c2
-rw-r--r--test/Parser/recovery.c2
-rw-r--r--test/Sema/c89.c3
-rw-r--r--test/Sema/function.c3
-rw-r--r--test/Sema/redefinition.c4
8 files changed, 19 insertions, 7 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 8d6cdcb696..57b967ec68 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -484,8 +484,9 @@ public:
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 b379ab2f02..42ce6c7a9f 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -720,6 +720,8 @@ DIAG(err_missing_param, ERROR,
"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 424ce7f845..6ef9ecd817 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -720,6 +720,11 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
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 eff69aca2d..5fe15d177d 100644
--- a/test/CodeGen/rdr-6140807-alias-references-forward.c
+++ b/test/CodeGen/rdr-6140807-alias-references-forward.c
@@ -10,5 +10,5 @@ int y() {
return f(1.);
}
-int x(int) {
+int x(int a) {
}
diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c
index f77b570638..78addb90e4 100644
--- a/test/Parser/recovery.c
+++ b/test/Parser/recovery.c
@@ -20,7 +20,7 @@ static char *f (char * (*g) (char **, int), char **p, ...) {
// 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 70949f0c82..b1780e9161 100644
--- a/test/Sema/c89.c
+++ b/test/Sema/c89.c
@@ -44,7 +44,8 @@ test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'
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 7c67bbaa63..f2aa8d9216 100644
--- a/test/Sema/function.c
+++ b/test/Sema/function.c
@@ -29,3 +29,6 @@ int t9(int a, ); // expected-error {{expected parameter declarator}}
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 9ad77f61a7..5e79070623 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'}}