1 // RUN: split-file %s %t
2 // RUN: %clang -cc1 -load %llvmshlibdir/Attribute%pluginext -fsyntax-only -ast-dump -verify %t/good_attr.cpp | FileCheck %s
3 // RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -fsyntax-only -Xclang -verify %t/bad_attr.cpp
4 // REQUIRES: plugins, examples
5 //--- good_attr.cpp
6 // expected-no-diagnostics
fn1a()7 void fn1a() __attribute__((example)) {}
fn1b()8 [[example]] void fn1b() {}
fn1c()9 [[plugin::example]] void fn1c() {}
fn2()10 void fn2() __attribute__((example("somestring", 1, 2.0))) {}
11 // CHECK-COUNT-4: -AnnotateAttr 0x{{[0-9a-z]+}} {{<col:[0-9]+(, col:[0-9]+)?>}} "example"
12 // CHECK: -StringLiteral 0x{{[0-9a-z]+}} {{<col:[0-9]+(, col:[0-9]+)?>}} 'const char[{{[0-9]+}}]' lvalue "somestring"
13 // CHECK: -IntegerLiteral 0x{{[0-9a-z]+}} {{<col:[0-9]+(, col:[0-9]+)?>}} 'int' 1
14 // CHECK: -FloatingLiteral 0x{{[0-9a-z]+}} {{<col:[0-9]+(, col:[0-9]+)?>}} 'double' 2.000000e+00
15 
16 //--- bad_attr.cpp
17 int var1 __attribute__((example("otherstring"))) = 1; // expected-warning {{'example' attribute only applies to functions}}
18 class Example {
19   void __attribute__((example)) fn3(); // expected-error {{'example' attribute only allowed at file scope}}
20 };
fn4()21 void fn4() __attribute__((example(123))) { } // expected-error {{first argument to the 'example' attribute must be a string literal}}
fn5()22 void fn5() __attribute__((example("a","b", 3, 4.0))) { } // expected-error {{'example' attribute only accepts at most three arguments}}
23