diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-16 22:50:01 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-16 22:50:01 +0000 |
commit | a3ca4d655974ad66e432a6c78dd08b277a639edf (patch) | |
tree | e21110f61d8e1c17f2ee1c640230ffe3b4446725 /test/Preprocessor | |
parent | 37f953f021c67e3b97f1ef38e1ef3cb08bd9d146 (diff) |
Don't allow #include (and its friends #import, #include_next and
#__include_macros) in the arguments of a function-style macro. Directives in the
arguments of such macros have undefined behaviour, and GCC does not correctly
support these cases. In some situations, this can lead to better diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146765 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Preprocessor')
-rw-r--r-- | test/Preprocessor/macro_arg_directive.c | 20 | ||||
-rw-r--r-- | test/Preprocessor/macro_arg_directive.h | 9 |
2 files changed, 29 insertions, 0 deletions
diff --git a/test/Preprocessor/macro_arg_directive.c b/test/Preprocessor/macro_arg_directive.c new file mode 100644 index 0000000000..5c9943d605 --- /dev/null +++ b/test/Preprocessor/macro_arg_directive.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify + +// header1.h +void fail(const char *); +#define MUNCH(...) \ + ({ int result = 0; __VA_ARGS__; if (!result) { fail(#__VA_ARGS__); }; result }) + +static inline int f(int k) { + return MUNCH( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{returning 'void'}} + if (k < 3) + result = 24; + else if (k > 4) + result = k - 4; +} + +#include "macro_arg_directive.h" // expected-error {{embedding a #include directive within macro arguments is not supported}} + +int g(int k) { + return f(k) + f(k-1)); +} diff --git a/test/Preprocessor/macro_arg_directive.h b/test/Preprocessor/macro_arg_directive.h new file mode 100644 index 0000000000..892dbf2b13 --- /dev/null +++ b/test/Preprocessor/macro_arg_directive.h @@ -0,0 +1,9 @@ +// Support header for macro_arg_directive.c + +int n; + +struct S { + int k; +}; + +void g(int); |