1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
29f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith
321c8fa87a3517d835072193a59a955ec7f6bf408Richard Smithusing size_t = decltype(sizeof(int));
421c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith
59f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithstruct S {
6176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  constexpr int f(); // expected-warning {{C++14}}
71bf9a9e6a5bdc0de7939908855dcddf46b661800Richard Smith  constexpr int g() const;
8176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  constexpr int h(); // expected-warning {{C++14}}
9714fcc1bcb42508983f9fd3435aa1dcd06212a8cRichard Smith  int h();
101bf9a9e6a5bdc0de7939908855dcddf46b661800Richard Smith  static constexpr int Sf();
1121c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  /*static*/ constexpr void *operator new(size_t) noexcept;
12176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  template<typename T> constexpr T tm(); // expected-warning {{C++14}}
1321c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  template<typename T> static constexpr T ts();
149f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith};
159f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith
169f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithvoid f(const S &s) {
179f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  s.f();
189f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  s.g();
191bf9a9e6a5bdc0de7939908855dcddf46b661800Richard Smith
2021c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  int (*Sf)() = &S::Sf;
2121c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  int (S::*f)() const = &S::f;
221bf9a9e6a5bdc0de7939908855dcddf46b661800Richard Smith  int (S::*g)() const = &S::g;
2321c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  void *(*opNew)(size_t) = &S::operator new;
2421c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  int (S::*tm)() const = &S::tm;
2521c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith  int (*ts)() = &S::ts;
269f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}
279f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith
2821c8fa87a3517d835072193a59a955ec7f6bf408Richard Smithconstexpr int S::f() const { return 0; }
29176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesconstexpr int S::g() { return 1; } // expected-warning {{C++14}}
30176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesconstexpr int S::h() { return 0; } // expected-warning {{C++14}}
31714fcc1bcb42508983f9fd3435aa1dcd06212a8cRichard Smithint S::h() { return 0; }
3221c8fa87a3517d835072193a59a955ec7f6bf408Richard Smithconstexpr int S::Sf() { return 2; }
3321c8fa87a3517d835072193a59a955ec7f6bf408Richard Smithconstexpr void *S::operator new(size_t) noexcept { return 0; }
34176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinestemplate<typename T> constexpr T S::tm() { return T(); } // expected-warning {{C++14}}
3521c8fa87a3517d835072193a59a955ec7f6bf408Richard Smithtemplate<typename T> constexpr T S::ts() { return T(); }
3621c8fa87a3517d835072193a59a955ec7f6bf408Richard Smith
379f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithnamespace std_example {
389f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith
390e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  class debug_flag {
409f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  public:
419f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith    explicit debug_flag(bool);
420e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    constexpr bool is_on() const; // ok (dr1684)
439f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  private:
449f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith    bool flag;
459f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  };
469f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith
479f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  constexpr int bar(int x, int y) // expected-note {{here}}
489f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith    { return x + y + x*y; }
499f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith  int bar(int x, int y) // expected-error {{non-constexpr declaration of 'bar' follows constexpr declaration}}
509f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith    { return x * 2 + 3 * y; }
519f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith
529f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}
539ec0ef31c3bc40612e8bf47bd7d265d5e7c01ff9Eli Friedman
549ec0ef31c3bc40612e8bf47bd7d265d5e7c01ff9Eli Friedman// The constexpr specifier is allowed for static member functions of non-literal types.
559ec0ef31c3bc40612e8bf47bd7d265d5e7c01ff9Eli Friedmanclass NonLiteralClass {
569ec0ef31c3bc40612e8bf47bd7d265d5e7c01ff9Eli Friedman  NonLiteralClass(bool);
579ec0ef31c3bc40612e8bf47bd7d265d5e7c01ff9Eli Friedman  static constexpr bool isDebugFlag();
589ec0ef31c3bc40612e8bf47bd7d265d5e7c01ff9Eli Friedman};
59