[cfe-commits] r147973 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/c11-typedef-redef.c
Eli Friedman
eli.friedman at gmail.com
Wed Jan 11 14:45:53 PST 2012
On Wed, Jan 11, 2012 at 2:33 PM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Wed Jan 11 16:33:48 2012
> New Revision: 147973
>
> URL: http://llvm.org/viewvc/llvm-project?rev=147973&view=rev
> Log:
> Improve the diagnostic when trying to redefine a typedef with a
> variably-modified type.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/c11-typedef-redef.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=147973&r1=147972&r2=147973&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jan 11 16:33:48 2012
> @@ -2754,6 +2754,8 @@
> def warn_redefinition_of_typedef : ExtWarn<
> "redefinition of typedef %0 is a C11 feature">,
> InGroup<DiagGroup<"typedef-redefinition"> >;
> +def err_redefinition_variably_modified_typedef : Error<
> + "redefinition of %select{typedef|type alias}0 for variably-modified type %1">;
>
> 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=147973&r1=147972&r2=147973&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan 11 16:33:48 2012
> @@ -1383,10 +1383,21 @@
> OldType = Context.getTypeDeclType(Old);
> QualType NewType = New->getUnderlyingType();
>
> + if (NewType->isVariablyModifiedType()) {
> + // Must not redefine a typedef with a variably-modified type.
> + int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
> + Diag(New->getLocation(), diag::err_redefinition_variably_modified_typedef)
> + << Kind << NewType;
> + if (Old->getLocation().isValid())
> + Diag(Old->getLocation(), diag::note_previous_definition);
> + New->setInvalidDecl();
> + return true;
> + }
> +
> if (OldType != NewType &&
> !OldType->isDependentType() &&
> !NewType->isDependentType() &&
> - !Context.hasSameType(OldType, NewType)) {
> + !Context.hasSameType(OldType, NewType)) {
> int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
> Diag(New->getLocation(), diag::err_redefinition_different_typedef)
> << Kind << NewType << OldType;
>
> Modified: cfe/trunk/test/Sema/c11-typedef-redef.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c11-typedef-redef.c?rev=147973&r1=147972&r2=147973&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/c11-typedef-redef.c (original)
> +++ cfe/trunk/test/Sema/c11-typedef-redef.c Wed Jan 11 16:33:48 2012
> @@ -10,5 +10,5 @@
> 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]')}}
> + typedef int vla[N]; // expected-error{{redefinition of typedef for variably-modified type 'int [N]'}}
> }
Might be nice to have a testcase for:
typedef int vla[N];
typedef vla vla2;
typedef vla vla2;
-Eli
More information about the cfe-commits
mailing list