diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-11 04:25:01 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-11 04:25:01 +0000 |
commit | c0004df84fca9225b66a50adc66cf21c34298227 (patch) | |
tree | 53fb95824e0ad18eaf33f7d6d1ca0d49a9e0358f | |
parent | 983d835bead0134170a6646a8844926077c968d6 (diff) |
C11 allows typedefs to be redefined. Implement this in C11 mode, and
downgrade the default-error warning to an ExtWarn in
C90/99. <rdar://problem/10668057>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147925 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 6 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 6 | ||||
-rw-r--r-- | test/Preprocessor/line-directive.c | 4 | ||||
-rw-r--r-- | test/Sema/c11-typedef-redef.c | 14 |
4 files changed, 21 insertions, 9 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index d4a07ee896..74189ca947 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2751,9 +2751,9 @@ def warn_undefined_internal : Warning< DiagGroup<"undefined-internal">; def note_used_here : Note<"used here">; -def warn_redefinition_of_typedef : Warning< - "redefinition of typedef %0 is invalid in C">, - InGroup<DiagGroup<"typedef-redefinition"> >, DefaultError; +def warn_redefinition_of_typedef : ExtWarn< + "redefinition of typedef %0 is a C11 feature">, + InGroup<DiagGroup<"typedef-redefinition"> >; def err_inline_declaration_block_scope : Error< "inline declaration of %0 not allowed in block scope">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a2bf48e47a..588fc14044 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1463,8 +1463,6 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) { // The types match. Link up the redeclaration chain if the old // declaration was a typedef. - // FIXME: this is a potential source of weirdness if the type - // spellings don't match exactly. if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Old)) New->setPreviousDeclaration(Typedef); @@ -1509,8 +1507,8 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) { return New->setInvalidDecl(); } - // Modules always permit redefinition of typedefs. - if (getLangOptions().Modules) + // Modules always permit redefinition of typedefs, as does C11. + if (getLangOptions().Modules || getLangOptions().C11) return; // If we have a redefinition of a typedef in C, emit a warning. This warning diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c index 878d067a30..102469449e 100644 --- a/test/Preprocessor/line-directive.c +++ b/test/Preprocessor/line-directive.c @@ -41,7 +41,7 @@ # 192 "glomp.h" // not a system header. typedef int x; // expected-note {{previous definition is here}} -typedef int x; // expected-error {{redefinition of typedef 'x' is invalid in C}} +typedef int x; // expected-warning {{redefinition of typedef 'x' is a C11 feature}} # 192 "glomp.h" 3 // System header. typedef int y; // ok @@ -62,7 +62,7 @@ typedef int z1; // ok # 42 "blonk.h" // DOES change system headerness. typedef int w; // expected-note {{previous definition is here}} -typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C}} +typedef int w; // expected-warning {{redefinition of typedef 'w' is a C11 feature}} typedef int q; // original definition in system header, should not diagnose. diff --git a/test/Sema/c11-typedef-redef.c b/test/Sema/c11-typedef-redef.c new file mode 100644 index 0000000000..7e213f49cf --- /dev/null +++ b/test/Sema/c11-typedef-redef.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -std=c11 %s -verify + +typedef int type; +typedef type type; +typedef int type; + +void f(int N) { + typedef int type2; + typedef type type2; + typedef int type2; + + typedef int vla[N]; // expected-note{{previous definition is here}} + typedef int vla[N]; // expected-error{{typedef redefinition with different types ('int [N]' vs 'int [N]')}} +} |