[clang] 39eef2c - PR43775: don't produce a bogus 'auto' -Wc++98-compat warning for CTAD

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 27 21:43:30 PDT 2019


Author: Richard Smith
Date: 2019-10-27T21:42:58-07:00
New Revision: 39eef2cbb6ab1fda2e0beb8789cd49a3ce276b16

URL: https://github.com/llvm/llvm-project/commit/39eef2cbb6ab1fda2e0beb8789cd49a3ce276b16
DIFF: https://github.com/llvm/llvm-project/commit/39eef2cbb6ab1fda2e0beb8789cd49a3ce276b16.diff

LOG: PR43775: don't produce a bogus 'auto' -Wc++98-compat warning for CTAD

Added: 
    

Modified: 
    clang/lib/Sema/SemaType.cpp
    clang/test/SemaCXX/cxx98-compat.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 02fc81105037..aa795e7b0656 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3139,7 +3139,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
 
       T = SemaRef.Context.IntTy;
       D.setInvalidType(true);
-    } else if (!HaveTrailing &&
+    } else if (Auto && !HaveTrailing &&
                D.getContext() != DeclaratorContext::LambdaExprContext) {
       // If there was a trailing return type, we already got
       // warn_cxx98_compat_trailing_return_type in the parser.

diff  --git a/clang/test/SemaCXX/cxx98-compat.cpp b/clang/test/SemaCXX/cxx98-compat.cpp
index 885ab110ab1f..e221259859bc 100644
--- a/clang/test/SemaCXX/cxx98-compat.cpp
+++ b/clang/test/SemaCXX/cxx98-compat.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s
 // RUN: %clang_cc1 -fsyntax-only -std=c++14 -Wc++98-compat -verify %s -DCXX14COMPAT
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++98-compat -verify %s -DCXX14COMPAT -DCXX17COMPAT
 
 namespace std {
   struct type_info;
@@ -180,12 +181,16 @@ void LocalTemplateArg() {
 struct {} obj_of_unnamed_type; // expected-note {{here}}
 int UnnamedTemplateArg = TemplateFn(obj_of_unnamed_type); // expected-warning {{unnamed type as template argument is incompatible with C++98}}
 
+// FIXME: We do not implement C++98 compatibility warnings for the C++17
+// template argument evaluation rules.
+#ifndef CXX17COMPAT
 namespace RedundantParensInAddressTemplateParam {
   int n;
   template<int*p> struct S {};
   S<(&n)> s; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
   S<(((&n)))> t; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
 }
+#endif
 
 namespace TemplateSpecOutOfScopeNs {
   template<typename T> struct S {};
@@ -299,6 +304,9 @@ namespace LiteralUCNs {
   const wchar_t *s2 = L"bar\u0085"; // expected-warning {{universal character name referring to a control character is incompatible with C++98}}
 }
 
+// FIXME: We do not implement C++98 compatibility warnings for the C++17
+// template argument evaluation rules.
+#ifndef CXX17COMPAT
 namespace NonTypeTemplateArgs {
   template<typename T, T v> struct S {};
   const int k = 5; // expected-note {{here}}
@@ -314,6 +322,7 @@ namespace NullPointerTemplateArg {
   X<(int*)0> x; // expected-warning {{use of null pointer as non-type template argument is incompatible with C++98}}
   Y<(int A::*)0> y; // expected-warning {{use of null pointer as non-type template argument is incompatible with C++98}}
 }
+#endif
 
 namespace PR13480 {
   struct basic_iterator {
@@ -400,3 +409,11 @@ float fsvar = B::v<float>;
 #ifdef CXX14COMPAT
 int digit_seps = 123'456; // expected-warning {{digit separators are incompatible with C++ standards before C++14}}
 #endif
+
+#ifdef CXX17COMPAT
+template<class T> struct CTAD {};
+void ctad_test() {
+  CTAD<int> s;
+  CTAD t = s; // expected-warning {{class template argument deduction is incompatible with C++ standards before C++17}}
+}
+#endif


        


More information about the cfe-commits mailing list