diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2009-02-20 01:34:21 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2009-02-20 01:34:21 +0000 |
| commit | ce98257691a97ea5cbf96a8349935e4fdf724deb (patch) | |
| tree | 81b6fab92838cd186cb53b3d27112f99e2860bed /clang | |
| parent | 92cfae68e9b8be247dc2f23cbcb4505d156587d3 (diff) | |
| download | bcm5719-llvm-ce98257691a97ea5cbf96a8349935e4fdf724deb.tar.gz bcm5719-llvm-ce98257691a97ea5cbf96a8349935e4fdf724deb.zip | |
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.)
llvm-svn: 65101
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 6 | ||||
| -rw-r--r-- | clang/test/Sema/invalid-init-diag.c | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7b54b8bc7c8..5a18aeb0acc 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2457,7 +2457,8 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) { 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 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) { 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); } diff --git a/clang/test/Sema/invalid-init-diag.c b/clang/test/Sema/invalid-init-diag.c new file mode 100644 index 00000000000..8eaefa6cd10 --- /dev/null +++ b/clang/test/Sema/invalid-init-diag.c @@ -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>'}} |

