• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2 
3 using size_t = decltype(sizeof(int));
4 
5 struct S {
6   constexpr int f(); // expected-warning {{C++14}}
7   constexpr int g() const;
8   constexpr int h(); // expected-warning {{C++14}}
9   int h();
10   static constexpr int Sf();
11   /*static*/ constexpr void *operator new(size_t) noexcept;
12   template<typename T> constexpr T tm(); // expected-warning {{C++14}}
13   template<typename T> static constexpr T ts();
14 };
15 
f(const S & s)16 void f(const S &s) {
17   s.f();
18   s.g();
19 
20   int (*Sf)() = &S::Sf;
21   int (S::*f)() const = &S::f;
22   int (S::*g)() const = &S::g;
23   void *(*opNew)(size_t) = &S::operator new;
24   int (S::*tm)() const = &S::tm;
25   int (*ts)() = &S::ts;
26 }
27 
f() const28 constexpr int S::f() const { return 0; }
g()29 constexpr int S::g() { return 1; } // expected-warning {{C++14}}
h()30 constexpr int S::h() { return 0; } // expected-warning {{C++14}}
h()31 int S::h() { return 0; }
Sf()32 constexpr int S::Sf() { return 2; }
operator new(size_t)33 constexpr void *S::operator new(size_t) noexcept { return 0; }
tm()34 template<typename T> constexpr T S::tm() { return T(); } // expected-warning {{C++14}}
ts()35 template<typename T> constexpr T S::ts() { return T(); }
36 
37 namespace std_example {
38 
39   class debug_flag {
40   public:
41     explicit debug_flag(bool);
42     constexpr bool is_on() const; // ok (dr1684)
43   private:
44     bool flag;
45   };
46 
bar(int x,int y)47   constexpr int bar(int x, int y) // expected-note {{here}}
48     { return x + y + x*y; }
bar(int x,int y)49   int bar(int x, int y) // expected-error {{non-constexpr declaration of 'bar' follows constexpr declaration}}
50     { return x * 2 + 3 * y; }
51 
52 }
53 
54 // The constexpr specifier is allowed for static member functions of non-literal types.
55 class NonLiteralClass {
56   NonLiteralClass(bool);
57   static constexpr bool isDebugFlag();
58 };
59