llvm-project/clang/test/Frontend/plugin-attribute-pp.cpp
Anders Waldenborg 1285a495d5 [clang][pp] Handle attributes defined by plugin in __has_attribute
When using attributes by plugins (both in clang and clang-tidy) the
preprocessor functions `__has_attribute`, `__has_c_attribute`,
`__has_cpp_attribute` still returned 0.

That problem is fixed by having the "hasAttribute" function also check
if any of the plugins provide that attribute.

This also adds C2x spelling to the example plugin for attributes so that
`__has_c_attribute` can be tested.

Differential Revision: https://reviews.llvm.org/D144405
2023-03-13 16:47:51 +01:00

29 lines
858 B
C++

// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -E %s | FileCheck %s
// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -E %s -x c | FileCheck %s
// REQUIRES: plugins, examples
#ifdef __cplusplus
# define HAS_ATTR(a) __has_cpp_attribute (a)
#else
# define HAS_ATTR(a) __has_c_attribute (a)
#endif
#if __has_attribute(example)
// CHECK: has_attribute(example) was true
has_attribute(example) was true
#endif
#if HAS_ATTR(example)
// CHECK: has_$LANG_attribute(example) was true
has_$LANG_attribute(example) was true
#endif
#if __has_attribute(doesnt_exist)
// CHECK-NOT: has_attribute(doesnt_exist) unexpectedly was true
has_attribute(doesnt_exist) unexpectedly was true
#endif
#if HAS_ATTR(doesnt_exist)
// CHECK-NOT: has_$LANG_attribute(doesnt_exist) unexpectedly was true
has_$LANG_attribute(doesnt_exist) unexpectedly was true
#endif