constant-expression-cxx11.cpp revision c49bd11f96c2378969822f1f1b814ffa8f2bfee4
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3template<typename T> constexpr T id(const T &t) { return t; }
4
5struct MemberZero {
6  constexpr int zero() { return 0; }
7};
8
9namespace TemplateArgumentConversion {
10  template<int n> struct IntParam {};
11
12  using IntParam0 = IntParam<0>;
13  // FIXME: This should be accepted once we do constexpr function invocation.
14  using IntParam0 = IntParam<id(0)>; // expected-error {{not an integral constant expression}}
15  using IntParam0 = IntParam<MemberZero().zero>; // expected-error {{did you mean to call it with no arguments?}} expected-error {{not an integral constant expression}}
16}
17
18namespace CaseStatements {
19  void f(int n) {
20    switch (n) {
21    // FIXME: Produce the 'add ()' fixit for this.
22    case MemberZero().zero: // desired-error {{did you mean to call it with no arguments?}} expected-error {{not an integer constant expression}}
23    // FIXME: This should be accepted once we do constexpr function invocation.
24    case id(1): // expected-error {{not an integer constant expression}}
25      return;
26    }
27  }
28}
29
30extern int &Recurse1;
31int &Recurse2 = Recurse1, &Recurse1 = Recurse2;
32constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}}
33
34namespace MemberEnum {
35  struct WithMemberEnum {
36    enum E { A = 42 };
37  } wme;
38  // FIXME: b's initializer is not treated as a constant expression yet, but we
39  // can at least fold it.
40  constexpr bool b = wme.A == 42;
41  int n[b];
42}
43