diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index e5a07962d83b..11d58ed2eb79 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/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/clang/test/CXX/over/over.match/over.match.best/p1.cpp b/clang/test/CXX/over/over.match/over.match.best/p1.cpp index 59e3dac74283..fad5bf9a72ee 100644 --- a/clang/test/CXX/over/over.match/over.match.best/p1.cpp +++ b/clang/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/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp index edc657c252e8..ebff0a1df4e7 100644 --- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp +++ b/clang/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/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp index 5fc1722e942b..359deedbee7a 100644 --- a/clang/test/Lexer/cxx-features.cpp +++ b/clang/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/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 4743e38ba1c8..6b45a8bb2ae0 100644 --- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/clang/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/clang/www/cxx_status.html b/clang/www/cxx_status.html index 6adf7fda8aee..6216a816455b 100644 --- a/clang/www/cxx_status.html +++ b/clang/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