summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2018-09-10 20:31:03 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2018-09-10 20:31:03 +0000
commit8eeb16f5d1008a3d3fc89e88d92b3bcebc36bba2 (patch)
tree515beea70adb40b91987b18587c4634a9ba4af7d
parent6dc896812423b7201492a116895df6c8c9601acf (diff)
downloadbcm5719-llvm-8eeb16f5d1008a3d3fc89e88d92b3bcebc36bba2.tar.gz
bcm5719-llvm-8eeb16f5d1008a3d3fc89e88d92b3bcebc36bba2.zip
Enhance -Wc++14-compat for class template argument deduction to list the
deduced type (if known). llvm-svn: 341858
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaInit.cpp17
-rw-r--r--clang/test/SemaCXX/cxx14-compat.cpp2
3 files changed, 14 insertions, 8 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3ff595c8e9c..b253a883d63 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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<
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 18a7aab1f5d..a25818f0fd3 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9139,13 +9139,13 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
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::DeduceTemplateSpecializationFromInitializer(
// 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;
}
diff --git a/clang/test/SemaCXX/cxx14-compat.cpp b/clang/test/SemaCXX/cxx14-compat.cpp
index 8b3dee8c822..d70f477cd09 100644
--- a/clang/test/SemaCXX/cxx14-compat.cpp
+++ b/clang/test/SemaCXX/cxx14-compat.cpp
@@ -16,7 +16,7 @@ namespace [[]] NS_with_attr {} // expected-warning {{incompatible with C++ stand
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
OpenPOWER on IntegriCloud