Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -x c++ -std=c++1y -fblocks -fsyntax-only -triple %itanium_abi_triple -verify %s
      2 // PR16946
      3 // expected-no-diagnostics
      4 
      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;
     10 }
     11 
     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;
     17 }
     18 
     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]");
     25 
     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;
     32   }
     33   ();
     34 
     35   ^{
     36     static_assert(sizeof(__func__) == 27, "___Z3bazIiEiv_block_invoke");
     37     static_assert(sizeof(__FUNCTION__) == 27, "___Z3bazIiEiv_block_invoke");
     38     static_assert(sizeof(__PRETTY_FUNCTION__) == 27, "___Z3bazIiEiv_block_invoke");
     39   }
     40   ();
     41 
     42   #pragma clang __debug captured
     43   {
     44     static_assert(sizeof(__func__) == 4, "baz");
     45     static_assert(sizeof(__FUNCTION__) == 4, "baz");
     46     static_assert(sizeof(__PRETTY_FUNCTION__) == 20, "int baz() [T = int]");
     47   }
     48 
     49   return 0;
     50 }
     51 
     52 int main() {
     53   static_assert(sizeof(__func__) == 5, "main");
     54   static_assert(sizeof(__FUNCTION__) == 5, "main");
     55   static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
     56 
     57   []() {
     58     static_assert(sizeof(__func__) == 11, "operator()");
     59     static_assert(sizeof(__FUNCTION__) == 11, "operator()");
     60     static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
     61                   "auto main()::<anonymous class>::operator()() const");
     62     return 0;
     63   }
     64   ();
     65 
     66   ^{
     67     static_assert(sizeof(__func__) == 20, "__main_block_invoke");
     68     static_assert(sizeof(__FUNCTION__) == 20, "__main_block_invoke");
     69     static_assert(sizeof(__PRETTY_FUNCTION__) == 20, "__main_block_invoke");
     70   }
     71   ();
     72 
     73   #pragma clang __debug captured
     74   {
     75     static_assert(sizeof(__func__) == 5, "main");
     76     static_assert(sizeof(__FUNCTION__) == 5, "main");
     77     static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
     78 
     79     #pragma clang __debug captured
     80     {
     81       static_assert(sizeof(__func__) == 5, "main");
     82       static_assert(sizeof(__FUNCTION__) == 5, "main");
     83       static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
     84     }
     85   }
     86 
     87   []() {
     88     #pragma clang __debug captured
     89     {
     90       static_assert(sizeof(__func__) == 11, "operator()");
     91       static_assert(sizeof(__FUNCTION__) == 11, "operator()");
     92       static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
     93                     "auto main()::<anonymous class>::operator()() const");
     94     }
     95   }
     96   ();
     97 
     98   baz<int>();
     99 
    100   return 0;
    101 }
    102