Clang Project

clang_source_code/test/SemaCXX/internal_linkage.cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2
3int f() __attribute__((internal_linkage));
4
5class A;
6class __attribute__((internal_linkage)) A {
7public:
8  int x __attribute__((internal_linkage)); // expected-warning{{'internal_linkage' attribute only applies to variables, functions, and classes}}
9  static int y __attribute__((internal_linkage));
10  void f1() __attribute__((internal_linkage));
11  void f2() __attribute__((internal_linkage)) {}
12  static void f3() __attribute__((internal_linkage)) {}
13  void f4(); // expected-note{{previous definition is here}}
14  static int zz; // expected-note{{previous definition is here}}
15  A() __attribute__((internal_linkage)) {}
16  ~A() __attribute__((internal_linkage)) {}
17  A& operator=(const A&) __attribute__((internal_linkage)) { return *this; }
18  struct {
19    int z  __attribute__((internal_linkage)); // expected-warning{{'internal_linkage' attribute only applies to}}
20  };
21};
22
23__attribute__((internal_linkage)) void A::f4() {} // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'f4'}}
24
25__attribute__((internal_linkage)) int A::zz; // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'zz'}}
26
27namespace Z __attribute__((internal_linkage)) { // expected-warning{{'internal_linkage' attribute only applies to}}
28}
29
30__attribute__((internal_linkage("foo"))) int g() {} // expected-error{{'internal_linkage' attribute takes no arguments}}
31
32[[clang::internal_linkage]] int h() {}
33
34enum struct __attribute__((internal_linkage)) E { // expected-warning{{'internal_linkage' attribute only applies to}}
35  a = 1,
36  b = 2
37};
38
39int A::y;
40
41void A::f1() {
42}
43
44void g(int a [[clang::internal_linkage]]) { // expected-warning{{'internal_linkage' attribute only applies to variables, functions and classes}}
45  int x [[clang::internal_linkage]]; // expected-warning{{'internal_linkage' attribute on a non-static local variable is ignored}}
46  static int y [[clang::internal_linkage]];
47}
48