attr-decl-after-definition.c revision d320ffc0f58df23eb0e698c79105a68de9c0e37a
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3void foo();
4void foo() __attribute__((unused));
5void foo() __attribute__((unused));
6void foo(){} // expected-note {{previous definition is here}}
7void foo() __attribute__((constructor)); // expected-warning {{must precede definition}}
8void foo();
9
10int bar;
11extern int bar;
12int bar;
13int bar __attribute__((weak));
14int bar __attribute__((used));
15extern int bar __attribute__((weak));
16int bar = 0; // expected-note {{previous definition is here}}
17int bar __attribute__((weak)); // no warning as it matches the existing
18                               // attribute.
19int bar __attribute__((used,
20                       visibility("hidden"))); // expected-warning {{must precede definition}}
21int bar;
22
23struct zed {  // expected-note {{previous definition is here}}
24};
25struct __attribute__((visibility("hidden"))) zed; // expected-warning {{must precede definition}}
26
27struct __attribute__((visibility("hidden"))) zed2 {
28};
29struct __attribute__((visibility("hidden"))) zed2;
30
31struct __attribute__((visibility("hidden"))) zed3 {  // expected-note {{previous definition is here}}
32};
33struct __attribute__((visibility("hidden"),
34                     packed  // expected-warning {{must precede definition}}
35                     )) zed3;
36
37struct __attribute__((visibility("hidden"))) zed4 {  // expected-note {{previous attribute is here}}
38};
39struct __attribute__((visibility("default"))) zed4; // expected-error {{visibility does not match previous declaration}}
40