1 // REQUIRES: x86-registered-target 2 // RUN: %clang_cc1 -triple x86_64-linux-gnu -verify=expected,enabled -emit-codegen-only %s 3 // RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-codegen-only -Wno-attribute-warning %s 4 5 __attribute__((error("oh no foo"))) void foo(void); 6 7 __attribute__((error("oh no bar"))) void bar(void); 8 9 int x(void) { 10 return 8 % 2 == 1; 11 } 12 13 __attribute__((warning("oh no quux"))) void quux(void); 14 15 __attribute__((error("demangle me"))) void __compiletime_assert_455(void); 16 17 __attribute__((error("one"), error("two"))) // expected-warning {{attribute 'error' is already applied with different arguments}} 18 void // expected-note@-1 {{previous attribute is here}} 19 duplicate_errors(void); 20 21 __attribute__((warning("one"), warning("two"))) // expected-warning {{attribute 'warning' is already applied with different arguments}} 22 void // expected-note@-1 {{previous attribute is here}} 23 duplicate_warnings(void); 24 25 void baz(void) { 26 foo(); // expected-error {{call to foo() declared with 'error' attribute: oh no foo}} 27 if (x()) 28 bar(); // expected-error {{call to bar() declared with 'error' attribute: oh no bar}} 29 30 quux(); // enabled-warning {{call to quux() declared with 'warning' attribute: oh no quux}} 31 __compiletime_assert_455(); // expected-error {{call to __compiletime_assert_455() declared with 'error' attribute: demangle me}} 32 duplicate_errors(); // expected-error {{call to duplicate_errors() declared with 'error' attribute: two}} 33 duplicate_warnings(); // enabled-warning {{call to duplicate_warnings() declared with 'warning' attribute: two}} 34 } 35 36 #ifdef __cplusplus 37 template <typename T> 38 __attribute__((error("demangle me, too"))) 39 T 40 nocall(T t); 41 42 struct Widget { 43 __attribute__((warning("don't call me!"))) 44 operator int() { return 42; } 45 }; 46 47 void baz_cpp(void) { 48 foo(); // expected-error {{call to foo() declared with 'error' attribute: oh no foo}} 49 if (x()) 50 bar(); // expected-error {{call to bar() declared with 'error' attribute: oh no bar}} 51 quux(); // enabled-warning {{call to quux() declared with 'warning' attribute: oh no quux}} 52 53 // Test that we demangle correctly in the diagnostic for C++. 54 __compiletime_assert_455(); // expected-error {{call to __compiletime_assert_455() declared with 'error' attribute: demangle me}} 55 nocall<int>(42); // expected-error {{call to int nocall<int>(int) declared with 'error' attribute: demangle me, too}} 56 57 Widget W; 58 int w = W; // enabled-warning {{Widget::operator int() declared with 'warning' attribute: don't call me!}} 59 } 60 #endif 61