Debian Codegraph @

gcc/testsuite/g++.dg/diagnostic/static_assert1.C

raw
1 // PR c++/97518
2 // { dg-do compile { target c++17 } }
3
4 template <typename T, typename U> struct is_same { static constexpr bool value = false; };
5 template <typename T> struct is_same<T, T> { static constexpr bool value = true; };
6
7 template <typename T> using some_metafunction_t = T;
8
9 template <typename T>
10 void foo(T ) {
11 using X = T*;
12 using Y = some_metafunction_t<T>;
13
14 static_assert(is_same<X, Y>::value); // { dg-error "static assertion failed" }
15 // { dg-message {.is_same<int\*, int>::value. evaluates to false} "" { target *-*-* } .-1 }
16 static_assert(is_same<X, Y>::value, "foo"); // { dg-error "static assertion failed: foo" }
17 // { dg-message {.is_same<int\*, int>::value. evaluates to false} "" { target *-*-* } .-1 }
18 static_assert(is_same<X, X>::value && is_same<X, Y>::value); // { dg-error "static assertion failed" }
19 // { dg-message {.is_same<int\*, int>::value. evaluates to false} "" { target *-*-* } .-1 }
20 static_assert(is_same<X, Y>::value && is_same<X, X>::value); // { dg-error "static assertion failed" }
21 // { dg-message {.is_same<int\*, int>::value. evaluates to false} "" { target *-*-* } .-1 }
22 static_assert(is_same<X, X>::value
23 && is_same<Y, Y>::value
24 && is_same<X, Y>::value); // { dg-error "static assertion failed" }
25 // { dg-message {.is_same<int\*, int>::value. evaluates to false} "" { target *-*-* } .-1 }
26 }
27
28 void bar() {
29 foo(0);
30 }