[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / predefined-expr.cpp
blob8cba0d41a2997f846208a7d5bfe61946e782df79
1 // RUN: %clang_cc1 -x c++ -std=c++1y -fblocks -fsyntax-only -triple %itanium_abi_triple -verify %s
2 // PR16946
3 // expected-no-diagnostics
5 auto foo() {
6 static_assert(sizeof(__func__) == 4, "foo");
7 static_assert(sizeof(__FUNCTION__) == 4, "foo");
8 static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "auto foo()");
9 return 0;
12 auto bar() -> decltype(42) {
13 static_assert(sizeof(__func__) == 4, "bar");
14 static_assert(sizeof(__FUNCTION__) == 4, "bar");
15 static_assert(sizeof(__PRETTY_FUNCTION__) == 10, "int bar()");
16 return 0;
19 // Within templates.
20 template <typename T>
21 int baz() {
22 static_assert(sizeof(__func__) == 4, "baz");
23 static_assert(sizeof(__FUNCTION__) == 4, "baz");
24 static_assert(sizeof(__PRETTY_FUNCTION__) == 20, "int baz() [T = int]");
26 []() {
27 static_assert(sizeof(__func__) == 11, "operator()");
28 static_assert(sizeof(__FUNCTION__) == 11, "operator()");
29 static_assert(sizeof(__PRETTY_FUNCTION__) == 50,
30 "auto baz()::<anonymous class>::operator()() const");
31 return 0;
33 ();
36 static_assert(sizeof(__func__) == 17, "baz_block_invoke");
37 static_assert(sizeof(__FUNCTION__) == 17, "baz_block_invoke");
38 static_assert(sizeof(__PRETTY_FUNCTION__) == 33, "int baz() [T = int]_block_invoke");
39 }();
41 #pragma clang __debug captured
43 static_assert(sizeof(__func__) == 4, "baz");
44 static_assert(sizeof(__FUNCTION__) == 4, "baz");
45 static_assert(sizeof(__PRETTY_FUNCTION__) == 20, "int baz() [T = int]");
48 return 0;
51 int main() {
52 static_assert(sizeof(__func__) == 5, "main");
53 static_assert(sizeof(__FUNCTION__) == 5, "main");
54 static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
56 []() {
57 static_assert(sizeof(__func__) == 11, "operator()");
58 static_assert(sizeof(__FUNCTION__) == 11, "operator()");
59 static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
60 "auto main()::<anonymous class>::operator()() const");
61 return 0;
63 ();
66 static_assert(sizeof(__func__) == 18, "main_block_invoke");
67 static_assert(sizeof(__FUNCTION__) == 18, "main_block_invoke");
68 static_assert(sizeof(__PRETTY_FUNCTION__) == 24, "int main()_block_invoke");
69 }();
71 #pragma clang __debug captured
73 static_assert(sizeof(__func__) == 5, "main");
74 static_assert(sizeof(__FUNCTION__) == 5, "main");
75 static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
77 #pragma clang __debug captured
79 static_assert(sizeof(__func__) == 5, "main");
80 static_assert(sizeof(__FUNCTION__) == 5, "main");
81 static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
85 []() {
86 #pragma clang __debug captured
88 static_assert(sizeof(__func__) == 11, "operator()");
89 static_assert(sizeof(__FUNCTION__) == 11, "operator()");
90 static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
91 "auto main()::<anonymous class>::operator()() const");
94 ();
96 baz<int>();
98 return 0;