blob: 23777240cbf7fea311a9bbd6d4121afe3664c7b4 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -Eonly -verify -pedantic %s
Chris Lattner01ecf832006-07-19 05:42:48 +00002// pasting ""x"" and ""+"" does not give a valid preprocessing token
Chris Lattner378d72c2009-05-28 05:41:32 +00003#define XYZ x ## +
4XYZ // expected-error {{pasting formed 'x+', an invalid preprocessing token}}
5#define XXYZ . ## test
6XXYZ // expected-error {{pasting formed '.test', an invalid preprocessing token}}
Chris Lattner01ecf832006-07-19 05:42:48 +00007
Chris Lattnerab9d51c2009-04-19 20:10:12 +00008// GCC PR 20077
Chris Lattnerab9d51c2009-04-19 20:10:12 +00009
10#define a a ## ## // expected-error {{'##' cannot appear at end of macro expansion}}
11#define b() b ## ## // expected-error {{'##' cannot appear at end of macro expansion}}
12#define c c ## // expected-error {{'##' cannot appear at end of macro expansion}}
13#define d() d ## // expected-error {{'##' cannot appear at end of macro expansion}}
14
15
16#define e ## ## e // expected-error {{'##' cannot appear at start of macro expansion}}
17#define f() ## ## f // expected-error {{'##' cannot appear at start of macro expansion}}
18#define g ## g // expected-error {{'##' cannot appear at start of macro expansion}}
19#define h() ## h // expected-error {{'##' cannot appear at start of macro expansion}}
20#define i ## // expected-error {{'##' cannot appear at start of macro expansion}}
21#define j() ## // expected-error {{'##' cannot appear at start of macro expansion}}
22
Chris Lattner1c1a00c2009-04-19 20:29:42 +000023// Invalid token pasting.
24// PR3918
25
26// When pasting creates poisoned identifiers, we error.
27#pragma GCC poison BLARG
28BLARG // expected-error {{attempt to use a poisoned identifier}}
29#define XX BL ## ARG
30XX // expected-error {{attempt to use a poisoned identifier}}
31
32#define VA __VA_ ## ARGS__
33int VA; // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
34
David Majnemer21db51a2013-11-05 10:05:58 +000035#define LOG_ON_ERROR(x) x ## #y; // expected-error {{'#' is not followed by a macro parameter}}
David Majnemer76faf1f2013-11-05 09:30:17 +000036LOG_ON_ERROR(0);
David Majnemerd3c3e782014-10-25 11:40:40 +000037
38#define PR21379A(x) printf ##x // expected-note {{macro 'PR21379A' defined here}}
39PR21379A(0 {, }) // expected-error {{too many arguments provided to function-like macro invocation}}
40 // expected-note@-1 {{parentheses are required around macro argument containing braced initializer list}}
41
42#define PR21379B(x) printf #x // expected-note {{macro 'PR21379B' defined here}}
43PR21379B(0 {, }) // expected-error {{too many arguments provided to function-like macro invocation}}
44 // expected-note@-1 {{parentheses are required around macro argument containing braced initializer list}}