// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -std=c++14 %s
// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -std=c++17 %s
// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -std=c++2a %s
// MSVC always adopted the C++17 rule that implies that constexpr variables are
// implicitly inline, so do the test again.
// RUN: %clang_cc1 -triple x86_64-windows-msvc -DMS_ABI -fsyntax-only -verify -std=c++11 %s
;
;
// valid declarations
constexpr int i1 = 0;
constexpr int
;
constexpr int s1::mi2 = 0;
// invalid declarations
// not a definition of an object
constexpr extern int i2; // expected-error {{constexpr variable declaration must be a definition}}
// not a literal type
constexpr notlit nl1; // expected-error {{constexpr variable cannot have non-literal type 'const notlit'}}
// function parameters
void // expected-error {{function parameter cannot be constexpr}}
// non-static member
;
// typedef
typedef constexpr int CI; // expected-error {{typedef cannot be constexpr}}
// tag
constexpr ; // expected-error {{class cannot be marked constexpr}}
constexpr ; // expected-error {{struct cannot be marked constexpr}}
constexpr ; // expected-error {{union cannot be marked constexpr}}
constexpr ; // expected-error {{enum cannot be marked constexpr}}
constexpr ; // expected-error {{class cannot be marked constexpr}}
constexpr ; // expected-error {{struct cannot be marked constexpr}}
constexpr ; // expected-error {{union cannot be marked constexpr}}
constexpr; // expected-error {{class cannot be marked constexpr}}
constexpr; // expected-error {{struct cannot be marked constexpr}}
constexpr; // expected-error {{union cannot be marked constexpr}}
constexpr; // expected-error {{enum cannot be marked constexpr}}
constexpr c3 = ;
constexpr s3 = ;
constexpr u3 = ;
constexpr e3 = V3;
constexpr c4 = ;
constexpr s4 = ;
constexpr u4 = ;
constexpr e4 = V4;
constexpr int; // expected-error {{constexpr can only be used in variable and function declarations}}
// redeclaration mismatch
constexpr int ; // expected-note {{previous declaration is here}}
int ; // expected-error {{non-constexpr declaration of 'f3' follows constexpr declaration}}
int ; // expected-note {{previous declaration is here}}
constexpr int ; // expected-error {{constexpr declaration of 'f4' follows non-constexpr declaration}}
constexpr T ;
constexpr T ; // expected-note {{previous}}
T ; // expected-error {{non-constexpr declaration of 'f5' follows constexpr declaration}}
T ; // expected-note {{here}}
constexpr T ; // expected-error {{constexpr declaration of 'f6' follows non-constexpr declaration}}
// destructor
;
// template stuff
constexpr T
T
;
// explicit specialization can differ in constepxr
notlit
char // expected-note {{previous}}
constexpr char ; // expected-error {{constexpr declaration of 'ft<char>' follows non-constexpr declaration}}
constexpr int
notlit
// expected-error@-2 {{no function template matches}}
constexpr int // expected-note {{previous}}
// expected-warning@-2 {{C++14}}
// expected-error@-4 {{does not match any declaration in 'S'}}
int ; // expected-error {{non-constexpr declaration of 'g<int>' follows constexpr declaration}}
// specializations can drop the 'constexpr' but not the implied 'const'.
char // expected-error {{no function template matches}}
double // ok
constexpr int i3 = ;
void
// Examples from the standard:
constexpr int ; // expected-note {{declared here}}
constexpr int bufsz = 1024;
constexpr ;
constexpr : , // expected-note {{undefined function 'square' cannot be used in a constant expression}}
constexpr pixel ; // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'pixel(2)'}}
constexpr int
constexpr pixel ;
int
extern constexpr int memsz; // expected-error {{constexpr variable declaration must be a definition}}