From ee8fbfe77883193c27ddc69435a480a057f1d15b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 14 Feb 2017 00:55:25 +0000 Subject: [PATCH] [c++1z] Add some more tests for class template argument deduction, add feature-test macro, and mark feature as done on status page. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295011 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/InitPreprocessor.cpp | 2 ++ .../over/over.match/over.match.best/p1.cpp | 24 ++++++++++++++++++- .../temp.deduct/temp.deduct.call/p3-0x.cpp | 17 +++++++++++++ test/Lexer/cxx-features.cpp | 8 +++++++ ...xx1z-class-template-argument-deduction.cpp | 20 ++++++++++++++++ www/cxx_status.html | 4 ++-- 6 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index e5a07962d8..11d58ed2eb 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -522,6 +522,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, Builder.defineMacro("__cpp_structured_bindings", "201606"); Builder.defineMacro("__cpp_nontype_template_args", "201411"); Builder.defineMacro("__cpp_fold_expressions", "201603"); + // FIXME: This is not yet listed in SD-6. + Builder.defineMacro("__cpp_deduction_guides", "201611"); } if (LangOpts.AlignedAllocation) Builder.defineMacro("__cpp_aligned_new", "201606"); diff --git a/test/CXX/over/over.match/over.match.best/p1.cpp b/test/CXX/over/over.match/over.match.best/p1.cpp index 59e3dac742..fad5bf9a72 100644 --- a/test/CXX/over/over.match/over.match.best/p1.cpp +++ b/test/CXX/over/over.match/over.match.best/p1.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s // expected-no-diagnostics template int &f0(T*, int); @@ -12,6 +12,28 @@ void test_f0(int* ip, void *vp) { float &fr = f0(vp, 0); } +namespace deduction_guide_example { + template struct A { + A(T, int*); + A(A&, int*); + enum { value }; + }; + + template struct remove_ref_impl; + template struct remove_ref_impl { using type = T; }; + template using remove_ref = typename remove_ref_impl::type; + + // FIXME: The standard's example is wrong; we add a remove_ref<...> here to + // fix it. + template::value> A(T&&, int*) -> A; + A a{1, 0}; + extern A a; + A b{a, 0}; + + A *pa = &a; + A&> *pb = &b; +} + // Partial ordering of function template specializations will be tested // elsewhere // FIXME: Initialization by user-defined conversion is tested elsewhere diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp index edc657c252..ebff0a1df4 100644 --- a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp @@ -73,4 +73,21 @@ namespace std_example { int n1 = f(i); int n2 = f(0); int n3 = g(i); // expected-error{{no matching function for call to 'g'}} + +#if __cplusplus > 201402L + template struct A { // expected-note {{candidate}} + template + A(T &&, U &&, int *); // expected-note {{[with T = int, U = int] not viable: no known conversion from 'int' to 'int &&'}} + A(T &&, int *); // expected-note {{requires 2}} + }; + template A(T &&, int *) -> A; // expected-note {{requires 2}} + + int *ip; + A a{i, 0, ip}; // expected-error {{no viable constructor or deduction guide}} + A a0{0, 0, ip}; + A a2{i, ip}; + + A &a0r = a0; + A &a2r = a2; +#endif } diff --git a/test/Lexer/cxx-features.cpp b/test/Lexer/cxx-features.cpp index 5fc1722e94..359deedbee 100644 --- a/test/Lexer/cxx-features.cpp +++ b/test/Lexer/cxx-features.cpp @@ -92,6 +92,14 @@ #error "wrong value for __cpp_nontype_template_args" #endif +#if check(template_template_args, 0, 0, 0, 0) // FIXME: should be 201611 when feature is enabled +#error "wrong value for __cpp_template_template_args" +#endif + +#if check(deduction_guides, 0, 0, 0, 201611) // FIXME: provisional name +#error "wrong value for __cpp_deduction_guides" +#endif + // --- C++14 features --- #if check(binary_literals, 0, 0, 201304, 201304) diff --git a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 4743e38ba1..6b45a8bb2a 100644 --- a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -117,3 +117,23 @@ namespace dependent { g("foo"); // expected-note {{instantiation of}} } } + +namespace look_into_current_instantiation { + template struct Q {}; + template struct A { + using U = T; + template using V = Q::U>; + template A(V); + }; + A a = Q(); // ok, can look through class-scope typedefs and alias + // templates, and members of the current instantiation + A &r = a; + + template struct B { // expected-note {{could not match 'B' against 'int'}} + struct X { + typedef T type; + }; + B(typename X::type); // expected-note {{couldn't infer template argument 'T'}} + }; + B b = 0; // expected-error {{no viable}} +} diff --git a/www/cxx_status.html b/www/cxx_status.html index 6adf7fda8a..6216a81645 100644 --- a/www/cxx_status.html +++ b/www/cxx_status.html @@ -684,11 +684,11 @@ as the draft C++1z standard evolves. Template argument deduction for class templates P0091R3 - Partial + SVN P0512R0 - Partial + SVN Non-type template parameters with auto type -- 2.40.0