c++: prvalue of array type [PR111286]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-ref13.C
blobf26027552a0db7dd9ca5fd5632981e4f505987d1
1 // P2280R4 - Using unknown pointers and references in constant expressions
2 // PR c++/106650
3 // { dg-do compile { target c++11 } }
5 using size_t = decltype(sizeof(42));
7 template <typename T, size_t N>
8 constexpr auto array_size(T (&)[N]) -> size_t {
9     return N;
12 extern int (&r)[42];
13 constexpr int i = array_size (r);
15 void check(int const (&param)[3]) {
16     int local[] = {1, 2, 3};
17     constexpr auto s0 = array_size(local);
18     constexpr auto s1 = array_size(param);
21 template <typename T, size_t N>
22 constexpr size_t array_size_ptr(T (*)[N]) {
23     return N;
26 void check_ptr(int const (*param)[3]) {
27     constexpr auto s2 = array_size_ptr(param); // { dg-error "not a constant" }
30 struct A
32    constexpr int f() { return 42; }
33    void g() { constexpr int i = f(); }
34    void g2() { constexpr int i = this->f(); }
37 struct B {
38   constexpr static bool b = false;
39   void g() noexcept(b) { }
40   void g2() noexcept(this->b) { }