r341858 - Enhance -Wc++14-compat for class template argument deduction to list the

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 10 13:31:03 PDT 2018


Author: rsmith
Date: Mon Sep 10 13:31:03 2018
New Revision: 341858

URL: http://llvm.org/viewvc/llvm-project?rev=341858&view=rev
Log:
Enhance -Wc++14-compat for class template argument deduction to list the
deduced type (if known).

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/cxx14-compat.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341858&r1=341857&r2=341858&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 10 13:31:03 2018
@@ -2153,7 +2153,8 @@ def note_deduction_guide_access : Note<
   "deduction guide declared %0 by intervening access specifier">;
 def warn_cxx14_compat_class_template_argument_deduction : Warning<
   "class template argument deduction is incompatible with C++ standards "
-  "before C++17">, InGroup<CXXPre17Compat>, DefaultIgnore;
+  "before C++17%select{|; for compatibility, use explicit type name %1}0">,
+  InGroup<CXXPre17Compat>, DefaultIgnore;
 
 // C++14 deduced return types
 def err_auto_fn_deduction_failure : Error<

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=341858&r1=341857&r2=341858&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Sep 10 13:31:03 2018
@@ -9139,13 +9139,13 @@ QualType Sema::DeduceTemplateSpecializat
     return QualType();
   }
 
-  Diag(TSInfo->getTypeLoc().getBeginLoc(),
-       diag::warn_cxx14_compat_class_template_argument_deduction)
-      << TSInfo->getTypeLoc().getSourceRange();
-
   // Can't deduce from dependent arguments.
-  if (Expr::hasAnyTypeDependentArguments(Inits))
+  if (Expr::hasAnyTypeDependentArguments(Inits)) {
+    Diag(TSInfo->getTypeLoc().getBeginLoc(),
+         diag::warn_cxx14_compat_class_template_argument_deduction)
+        << TSInfo->getTypeLoc().getSourceRange() << 0;
     return Context.DependentTy;
+  }
 
   // FIXME: Perform "exact type" matching first, per CWG discussion?
   //        Or implement this via an implied 'T(T) -> T' deduction guide?
@@ -9348,5 +9348,10 @@ QualType Sema::DeduceTemplateSpecializat
   // C++ [dcl.type.class.deduct]p1:
   //  The placeholder is replaced by the return type of the function selected
   //  by overload resolution for class template deduction.
-  return SubstAutoType(TSInfo->getType(), Best->Function->getReturnType());
+  QualType DeducedType =
+      SubstAutoType(TSInfo->getType(), Best->Function->getReturnType());
+  Diag(TSInfo->getTypeLoc().getBeginLoc(),
+       diag::warn_cxx14_compat_class_template_argument_deduction)
+      << TSInfo->getTypeLoc().getSourceRange() << 1 << DeducedType;
+  return DeducedType;
 }

Modified: cfe/trunk/test/SemaCXX/cxx14-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx14-compat.cpp?rev=341858&r1=341857&r2=341858&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx14-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx14-compat.cpp Mon Sep 10 13:31:03 2018
@@ -16,7 +16,7 @@ namespace [[]] NS_with_attr {} // expect
 enum { e [[]] }; // expected-warning {{incompatible with C++ standards before C++17}}
 
 template<typename T = int> struct X {};
-X x; // expected-warning {{class template argument deduction is incompatible with C++ standards before C++17}}
+X x; // expected-warning {{class template argument deduction is incompatible with C++ standards before C++17; for compatibility, use explicit type name 'X<int>'}}
 
 template<template<typename> class> struct Y {};
 Y<X> yx; // ok, not class template argument deduction




More information about the cfe-commits mailing list