<br><br><div class="gmail_quote">Le 11 janvier 2012 05:25, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>></span> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: dgregor<br>
Date: Tue Jan 10 22:25:01 2012<br>
New Revision: 147925<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=147925&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=147925&view=rev</a><br>
Log:<br>
C11 allows typedefs to be redefined. Implement this in C11 mode, and<br>
downgrade the default-error warning to an ExtWarn in<br>
C90/99. <rdar://problem/10668057><br>
<br>
Added:<br>
cfe/trunk/test/Sema/c11-typedef-redef.c (with props)<br>
Modified:<br>
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/test/Preprocessor/line-directive.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=147925&r1=147924&r2=147925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=147925&r1=147924&r2=147925&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 10 22:25:01 2012<br>
@@ -2751,9 +2751,9 @@<br>
DiagGroup<"undefined-internal">;<br>
def note_used_here : Note<"used here">;<br>
<br>
-def warn_redefinition_of_typedef : Warning<<br>
- "redefinition of typedef %0 is invalid in C">,<br>
- InGroup<DiagGroup<"typedef-redefinition"> >, DefaultError;<br>
+def warn_redefinition_of_typedef : ExtWarn<<br>
+ "redefinition of typedef %0 is a C11 feature">,<br>
+ InGroup<DiagGroup<"typedef-redefinition"> >;<br>
<br>
def err_inline_declaration_block_scope : Error<<br>
"inline declaration of %0 not allowed in block scope">;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=147925&r1=147924&r2=147925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=147925&r1=147924&r2=147925&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 10 22:25:01 2012<br>
@@ -1463,8 +1463,6 @@<br>
<br>
// The types match. Link up the redeclaration chain if the old<br>
// declaration was a typedef.<br>
- // FIXME: this is a potential source of weirdness if the type<br>
- // spellings don't match exactly.<br>
if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Old))<br>
New->setPreviousDeclaration(Typedef);<br>
<br>
@@ -1509,8 +1507,8 @@<br>
return New->setInvalidDecl();<br>
}<br>
<br>
- // Modules always permit redefinition of typedefs.<br>
- if (getLangOptions().Modules)<br>
+ // Modules always permit redefinition of typedefs, as does C11.<br>
+ if (getLangOptions().Modules || getLangOptions().C11)<br>
return;<br>
<br>
// If we have a redefinition of a typedef in C, emit a warning. This warning<br>
<br>
Modified: cfe/trunk/test/Preprocessor/line-directive.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=147925&r1=147924&r2=147925&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=147925&r1=147924&r2=147925&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Preprocessor/line-directive.c (original)<br>
+++ cfe/trunk/test/Preprocessor/line-directive.c Tue Jan 10 22:25:01 2012<br>
@@ -41,7 +41,7 @@<br>
<br>
# 192 "glomp.h" // not a system header.<br>
typedef int x; // expected-note {{previous definition is here}}<br>
-typedef int x; // expected-error {{redefinition of typedef 'x' is invalid in C}}<br>
+typedef int x; // expected-warning {{redefinition of typedef 'x' is a C11 feature}}<br>
<br>
# 192 "glomp.h" 3 // System header.<br>
typedef int y; // ok<br>
@@ -62,7 +62,7 @@<br>
# 42 "blonk.h" // DOES change system headerness.<br>
<br>
typedef int w; // expected-note {{previous definition is here}}<br>
-typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C}}<br>
+typedef int w; // expected-warning {{redefinition of typedef 'w' is a C11 feature}}<br>
<br>
typedef int q; // original definition in system header, should not diagnose.<br>
<br>
<br>
Added: cfe/trunk/test/Sema/c11-typedef-redef.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c11-typedef-redef.c?rev=147925&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c11-typedef-redef.c?rev=147925&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/c11-typedef-redef.c (added)<br>
+++ cfe/trunk/test/Sema/c11-typedef-redef.c Tue Jan 10 22:25:01 2012<br>
@@ -0,0 +1,14 @@<br>
+// RUN: %clang_cc1 -std=c11 %s -verify<br>
+<br>
+typedef int type;<br>
+typedef type type;<br>
+typedef int type;<br>
+<br>
+void f(int N) {<br>
+ typedef int type2;<br>
+ typedef type type2;<br>
+ typedef int type2;<br>
+<br>
+ typedef int vla[N]; // expected-note{{previous definition is here}}<br>
+ typedef int vla[N]; // expected-error{{typedef redefinition with different types ('int [N]' vs 'int [N]')}}<br>
+}<br><br></blockquote><div>Hello Doug,<br><br>this last error is very weird:<br>- is the error off ? (ie, it is acceptable to redefine the typedef for vla but not handled yet)<br>- or is it simply that the diagnostic is unclear ? (the FOO vs FOO part looks strange, the types are identical as far as I can see).<br>
<br>-- Matthieu <br></div></div>