[cfe-commits] r39294 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp include/clang/Basic/DiagnosticKinds.def
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:37 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:36 2007
New Revision: 39294
URL: http://llvm.org/viewvc/llvm-project?rev=39294&view=rev
Log:
Enforce C99 6.7.2.1p2:
t.c:5:8: error: field 'foo' declared as a function
void foo();
^
Modified:
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:36 2007
@@ -383,7 +383,7 @@
TagDecl *Record = static_cast<TagDecl*>(RecDecl);
if (Record->isDefinition()) {
// Diagnose code like:
- // struct S { struct S {} X; };
+ // struct S { struct S {} X; };
// We discover this when we complete the outer S. Reject and ignore the
// outer S.
Diag(Record->getLocation(), diag::err_nested_redefinition,
@@ -391,8 +391,30 @@
Diag(RecLoc, diag::err_previous_definition);
return;
}
-
+
+ // Okay, we successfully defined 'Record'.
Record->setDefinition(true);
+
+ // Verify that all the fields are okay.
+ for (unsigned i = 0; i != NumFields; ++i) {
+ FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
+ if (!FD) continue; // Already issued a diagnostic.
+
+ // C99 6.7.2.1p2 - A field may not be a function type.
+ if (isa<FunctionType>(FD->getType())) {
+ Diag(FD->getLocation(), diag::err_field_declared_as_function,
+ FD->getName());
+ continue;
+ }
+
+ // C99 6.7.2.1p2 - A field may not be an incomplete type except...
+ if (FD->getType()->isIncompleteType()) {
+
+ //
+
+ }
+ }
+
}
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:36 2007
@@ -383,7 +383,7 @@
TagDecl *Record = static_cast<TagDecl*>(RecDecl);
if (Record->isDefinition()) {
// Diagnose code like:
- // struct S { struct S {} X; };
+ // struct S { struct S {} X; };
// We discover this when we complete the outer S. Reject and ignore the
// outer S.
Diag(Record->getLocation(), diag::err_nested_redefinition,
@@ -391,8 +391,30 @@
Diag(RecLoc, diag::err_previous_definition);
return;
}
-
+
+ // Okay, we successfully defined 'Record'.
Record->setDefinition(true);
+
+ // Verify that all the fields are okay.
+ for (unsigned i = 0; i != NumFields; ++i) {
+ FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
+ if (!FD) continue; // Already issued a diagnostic.
+
+ // C99 6.7.2.1p2 - A field may not be a function type.
+ if (isa<FunctionType>(FD->getType())) {
+ Diag(FD->getLocation(), diag::err_field_declared_as_function,
+ FD->getName());
+ continue;
+ }
+
+ // C99 6.7.2.1p2 - A field may not be an incomplete type except...
+ if (FD->getType()->isIncompleteType()) {
+
+ //
+
+ }
+ }
+
}
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:42:36 2007
@@ -437,6 +437,9 @@
DIAG(ext_implicit_function_decl, EXTENSION,
"implicit declaration of function '%s' is invalid in C99")
+DIAG(err_field_declared_as_function, ERROR,
+ "field '%s' declared as a function")
+
// Expressions.
DIAG(ext_sizeof_function_type, EXTENSION,
"invalid application of 'sizeof' to a function type")
More information about the cfe-commits
mailing list