[cfe-commits] r65101 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/invalid-init-diag.c
Eli Friedman
eli.friedman at gmail.com
Thu Feb 19 17:34:21 PST 2009
Author: efriedma
Date: Thu Feb 19 19:34:21 2009
New Revision: 65101
URL: http://llvm.org/viewvc/llvm-project?rev=65101&view=rev
Log:
Suppress constant initializer checking when the declaration isn't valid.
This prevents emitting diagnostics which are almost certainly useless.
(Note that the test is checking that we emit only one diagnostic.)
Added:
cfe/trunk/test/Sema/invalid-init-diag.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=65101&r1=65100&r2=65101&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Feb 19 19:34:21 2009
@@ -2457,7 +2457,8 @@
VDecl->setInvalidDecl();
// C++ 3.6.2p2, allow dynamic initialization of static initializers.
- if (!getLangOptions().CPlusPlus) {
+ // Don't check invalid declarations to avoid emitting useless diagnostics.
+ if (!getLangOptions().CPlusPlus && !VDecl->isInvalidDecl()) {
if (SC == VarDecl::Static) // C99 6.7.8p4.
CheckForConstantInitializer(Init, DclT);
}
@@ -2471,7 +2472,8 @@
VDecl->setInvalidDecl();
// C++ 3.6.2p2, allow dynamic initialization of static initializers.
- if (!getLangOptions().CPlusPlus) {
+ // Don't check invalid declarations to avoid emitting useless diagnostics.
+ if (!getLangOptions().CPlusPlus && !VDecl->isInvalidDecl()) {
// C99 6.7.8p4. All file scoped initializers need to be constant.
CheckForConstantInitializer(Init, DclT);
}
Added: cfe/trunk/test/Sema/invalid-init-diag.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-init-diag.c?rev=65101&view=auto
==============================================================================
--- cfe/trunk/test/Sema/invalid-init-diag.c (added)
+++ cfe/trunk/test/Sema/invalid-init-diag.c Thu Feb 19 19:34:21 2009
@@ -0,0 +1,4 @@
+// RUN: clang %s -verify -fsyntax-only
+
+int a;
+struct {int x;} x = a; // expected-error {{incompatible type initializing 'int', expected 'struct <anonymous>'}}
More information about the cfe-commits
mailing list