[cfe-commits] r147925 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Preprocessor/line-directive.c test/Sema/c11-typedef-redef.c

Matthieu Monrocq matthieu.monrocq at gmail.com
Wed Jan 11 11:44:11 PST 2012


Le 11 janvier 2012 05:25, Douglas Gregor <dgregor at apple.com> a écrit :

> Author: dgregor
> Date: Tue Jan 10 22:25:01 2012
> New Revision: 147925
>
> URL: http://llvm.org/viewvc/llvm-project?rev=147925&view=rev
> Log:
> 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>
>
> Added:
>    cfe/trunk/test/Sema/c11-typedef-redef.c   (with props)
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/test/Preprocessor/line-directive.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=147925&r1=147924&r2=147925&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 10
> 22:25:01 2012
> @@ -2751,9 +2751,9 @@
>   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">;
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=147925&r1=147924&r2=147925&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 10 22:25:01 2012
> @@ -1463,8 +1463,6 @@
>
>   // 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 @@
>     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
>
> Modified: cfe/trunk/test/Preprocessor/line-directive.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=147925&r1=147924&r2=147925&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/line-directive.c (original)
> +++ cfe/trunk/test/Preprocessor/line-directive.c Tue Jan 10 22:25:01 2012
> @@ -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 @@
>  # 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.
>
>
> Added: cfe/trunk/test/Sema/c11-typedef-redef.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c11-typedef-redef.c?rev=147925&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Sema/c11-typedef-redef.c (added)
> +++ cfe/trunk/test/Sema/c11-typedef-redef.c Tue Jan 10 22:25:01 2012
> @@ -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]')}}
> +}
>
> Hello Doug,

this last error is very weird:
- is the error off ?   (ie, it is acceptable to redefine the typedef for
vla but not handled yet)
- 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).

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120111/a0363662/attachment.html>


More information about the cfe-commits mailing list