nickdesaulniers updated this revision to Diff 166578. nickdesaulniers marked an inline comment as done. nickdesaulniers added a comment.
- also run test on gnu99+ Repository: rC Clang https://reviews.llvm.org/D52248 Files: lib/Sema/SemaType.cpp test/Sema/gnu89-const.c Index: test/Sema/gnu89-const.c =================================================================== --- /dev/null +++ test/Sema/gnu89-const.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 %s -std=gnu89 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu89 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-GNU89-PEDANTIC %s +// RUN: %clang_cc1 %s -std=gnu99 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu99 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu11 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu11 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu17 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu17 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s + +// Do not warn about duplicate const declaration specifier as the result of +// typeof in gnu89, unless -pedantic was specified. Do not warn in gnu99+, even +// with -pedantic. +const int c_i; +const typeof(c_i) c_i2; +// CHECK-GNU89-PEDANTIC: 14:7: warning: extension used +// CHECK-GNU89-PEDANTIC: 14:1: warning: duplicate 'const' declaration specifier +// CHECK-ABSTRUSE-NOT: 14:1: warning: duplicate 'const' declaration specifier + +const const int c_i3; +// CHECK: 19:7: warning: duplicate 'const' declaration specifier + +typedef const int t; +const t c_i4; +// CHECK: 23:1: warning: duplicate 'const' declaration specifier Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1679,8 +1679,13 @@ // C90 6.5.3 constraints: "The same type qualifier shall not appear more // than once in the same specifier-list or qualifier-list, either directly // or via one or more typedefs." - if (!S.getLangOpts().C99 && !S.getLangOpts().CPlusPlus - && TypeQuals & Result.getCVRQualifiers()) { + // + // Not checked for gnu89 if the TST is from a typeof expression and + // -pedantic was not set. + if (!S.getLangOpts().C99 && !S.getLangOpts().CPlusPlus && + TypeQuals & Result.getCVRQualifiers() && + !(S.getLangOpts().GNUMode && !S.Diags.getDiagnosticOptions().Pedantic && + DS.getTypeSpecType() == DeclSpec::TST_typeofExpr)) { if (TypeQuals & DeclSpec::TQ_const && Result.isConstQualified()) { S.Diag(DS.getConstSpecLoc(), diag::ext_duplicate_declspec) << "const";
Index: test/Sema/gnu89-const.c =================================================================== --- /dev/null +++ test/Sema/gnu89-const.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 %s -std=gnu89 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu89 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-GNU89-PEDANTIC %s +// RUN: %clang_cc1 %s -std=gnu99 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu99 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu11 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu11 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu17 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s +// RUN: %clang_cc1 %s -std=gnu17 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-ABSTRUSE %s + +// Do not warn about duplicate const declaration specifier as the result of +// typeof in gnu89, unless -pedantic was specified. Do not warn in gnu99+, even +// with -pedantic. +const int c_i; +const typeof(c_i) c_i2; +// CHECK-GNU89-PEDANTIC: 14:7: warning: extension used +// CHECK-GNU89-PEDANTIC: 14:1: warning: duplicate 'const' declaration specifier +// CHECK-ABSTRUSE-NOT: 14:1: warning: duplicate 'const' declaration specifier + +const const int c_i3; +// CHECK: 19:7: warning: duplicate 'const' declaration specifier + +typedef const int t; +const t c_i4; +// CHECK: 23:1: warning: duplicate 'const' declaration specifier Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1679,8 +1679,13 @@ // C90 6.5.3 constraints: "The same type qualifier shall not appear more // than once in the same specifier-list or qualifier-list, either directly // or via one or more typedefs." - if (!S.getLangOpts().C99 && !S.getLangOpts().CPlusPlus - && TypeQuals & Result.getCVRQualifiers()) { + // + // Not checked for gnu89 if the TST is from a typeof expression and + // -pedantic was not set. + if (!S.getLangOpts().C99 && !S.getLangOpts().CPlusPlus && + TypeQuals & Result.getCVRQualifiers() && + !(S.getLangOpts().GNUMode && !S.Diags.getDiagnosticOptions().Pedantic && + DS.getTypeSpecType() == DeclSpec::TST_typeofExpr)) { if (TypeQuals & DeclSpec::TQ_const && Result.isConstQualified()) { S.Diag(DS.getConstSpecLoc(), diag::ext_duplicate_declspec) << "const";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits