[PATCH] D52248: [SEMA] ignore duplicate declaration specifiers from typeof exprs
Nick Desaulniers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 20 13:09:36 PDT 2018
nickdesaulniers updated this revision to Diff 166351.
nickdesaulniers added a comment.
- warn only if -pedantic, add gcc bug test cases
Repository:
rC Clang
https://reviews.llvm.org/D52248
Files:
lib/Sema/SemaType.cpp
test/Sema/gnu89.c
Index: test/Sema/gnu89.c
===================================================================
--- test/Sema/gnu89.c
+++ test/Sema/gnu89.c
@@ -1,5 +1,24 @@
-// RUN: %clang_cc1 %s -std=gnu89 -pedantic -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=gnu89 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-PEDANTIC %s
+// RUN: %clang_cc1 %s -std=gnu89 -fsyntax-only 2>&1 | FileCheck %s
int f(int restrict);
-void main() {} // expected-warning {{return type of 'main' is not 'int'}} expected-note {{change return type to 'int'}}
+void main() {}
+// CHECK: return type of 'main' is not 'int'
+// CHECK: change return type to 'int'
+
+// Do not warn about duplicate const declaration specifier as the result of
+// typeof in gnu89.
+const int c_i;
+const typeof(c_i) c_i3;
+// CHECK-PEDANTIC: warning: extension used
+// CHECK-PEDANTIC: warning: duplicate 'const' declaration specifier
+// CHECK-otherwise-NOT: warning: duplicate 'const' declaration specifier
+
+const const int x;
+// CHECK: warning: duplicate 'const' declaration specifier
+
+typedef const int t;
+const t x2;
+// CHECK: warning: duplicate 'const' declaration specifier
+
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1679,8 +1679,14 @@
// 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";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52248.166351.patch
Type: text/x-patch
Size: 2177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180920/ba1a0e88/attachment.bin>
More information about the cfe-commits
mailing list