// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s -DCLASS #ifdef CLASS struct Outer { #endif template struct A {}; // Valid forms. A(int(&)[1]) -> A; explicit A(int(&)[2]) -> A; // Declarator pieces are not OK. *A(int(&)[3]) -> A; // expected-error {{cannot specify any part of a return type in the declaration of a deduction guide}} &A(int(&)[4]) -> A; // expected-error {{cannot specify any part of a return type in the declaration of a deduction guide}} A(int(&)[5])[3] -> A; #ifdef CLASS // FIXME: These diagnostics are both pretty bad. // expected-error@-2 {{function cannot return array type}} expected-error@-2 {{';'}} #else // expected-error@-4 {{expected function body after function declarator}} #endif (A[3])(int(&)[5][1]) -> A; // expected-error {{'' cannot be the name of a variable}} #ifndef CLASS // expected-error@-2 {{declared as array of functions}} #endif (*A)(int(&)[5][2]) -> A; // expected-error {{'' cannot be the name of a variable}} (&A)(int(&)[5][3]) -> A; // expected-error {{'' cannot be the name of a variable}} (*A(int))(int(&)[5][4]) -> A; // expected-error {{cannot specify any part of a return type in the declaration of a deduction guide}} // (Pending DR) attributes and parens around the declarator-id are OK. [[deprecated]] A(int(&)[6]) [[]] -> A [[]]; A [[]] (int(&)[7]) -> A; (A)(int(&)[8]) -> A; // ... but the trailing-return-type is part of the function-declarator as normal (A(int(&)[9])) -> A; #ifdef CLASS // FIXME: These diagnostics are both pretty bad. // expected-error@-2 {{deduction guide declaration without trailing return type}} expected-error@-2 {{';'}} #else // expected-error@-4 {{expected function body after function declarator}} #endif (A(int(&)[10]) -> A); // expected-error {{trailing return type may not be nested within parentheses}} // A trailing-return-type is mandatory. A(int(&)[11]); // expected-error {{deduction guide declaration without trailing return type}} // No type specifier is permitted; we don't even parse such cases as a deduction-guide. int A(int) -> A; // expected-error {{function with trailing return type must specify return type 'auto', not 'int'}} template struct B {}; // expected-note {{here}} auto B(int) -> B; // expected-error {{redefinition of 'B' as different kind of symbol}} // No storage class specifier, function specifier, ... friend A(int(&)[20]) -> A; #ifdef CLASS // expected-error@-2 {{cannot declare a deduction guide as a friend}} #else // expected-error@-4 {{'friend' used outside of class}} #endif typedef A(int(&)[21]) -> A; // expected-error {{deduction guide cannot be declared 'typedef'}} constexpr A(int(&)[22]) -> A; // expected-error {{deduction guide cannot be declared 'constexpr'}} inline A(int(&)[23]) -> A; // expected-error {{deduction guide cannot be declared 'inline'}} static A(int(&)[24]) -> A; // expected-error {{deduction guide cannot be declared 'static'}} thread_local A(int(&)[25]) -> A; // expected-error {{'thread_local' is only allowed on variable declarations}} extern A(int(&)[26]) -> A; #ifdef CLASS // expected-error@-2 {{storage class specified for a member}} #else // expected-error@-4 {{deduction guide cannot be declared 'extern'}} #endif mutable A(int(&)[27]) -> A; // expected-error-re {{{{'mutable' cannot be applied to|illegal storage class on}} function}} virtual A(int(&)[28]) -> A; // expected-error {{'virtual' can only appear on non-static member functions}} const A(int(&)[31]) -> A; // expected-error {{deduction guide cannot be declared 'const'}} const volatile static constexpr inline A(int(&)[29]) -> A; // expected-error {{deduction guide cannot be declared 'static inline constexpr const volatile'}} A(int(&)[30]) const -> A; // expected-error {{deduction guide cannot have 'const' qualifier}} // No definition is allowed. A(int(&)[40]) -> A {} // expected-error {{deduction guide cannot have a function definition}} A(int(&)[41]) -> A = default; // expected-error {{deduction guide cannot have a function definition}} expected-error {{only special member functions may be defaulted}} A(int(&)[42]) -> A = delete; // expected-error {{deduction guide cannot have a function definition}} A(int(&)[43]) -> A try {} catch (...) {} // expected-error {{deduction guide cannot have a function definition}} #ifdef CLASS }; #endif namespace ExplicitInst { // Explicit instantiation / specialization is not permitted. template struct B {}; template B(T) -> B; template<> B(int) -> B; // expected-error {{deduction guide cannot be explicitly specialized}} extern template B(float) -> B; // expected-error {{deduction guide cannot be explicitly instantiated}} template B(char) -> B; // expected-error {{deduction guide cannot be explicitly instantiated}} // An attempt at partial specialization doesn't even parse as a deduction-guide. template B(T*) -> B; // expected-error 1+{{}} expected-note 0+{{}} struct X { template struct C {}; template C(T) -> C; template<> C(int) -> C; // expected-error {{deduction guide cannot be explicitly specialized}} extern template C(float) -> C; // expected-error {{expected member name or ';'}} template C(char) -> C; // expected-error {{expected '<' after 'template'}} }; }