Skip to content

[Clang] Implement P2843R3 - Preprocessing is never undefined #145658

Open
@cor3ntin

Description

@cor3ntin

Here are some test cases for this paper.
The limitations on line numbers may be a bit restrictive, show we ask WG21 to make that implementation defined?

We currently do not diagnose directives in arguments of function macros, so this should
probably comes with an opt-out mechanism

// [cpp.include]: nothing to do
#define FOO invalid
#include FOO
// expected-error@-1 {{expected "FILENAME" or <FILENAME>}}

// [cpp.cond]
#define DEFINED defined
#if DEFINED(bar) // Should be an error 
#endif

// [cpp.replace.general] 
#define FUNCTION_MACRO(...)
FUNCTION_MACRO(
    #if 0 // should diagnose
    #endif
)

// [cpp.stringize]: nothing to do
#define STR(x) # x
const char* a = STR(\o{999});


// [cpp.concat]: nothing to do
#define CONCAT(A, B) A ## B
CONCAT(=, >)
// expected-error@-1 {{pasting formed '=>', an invalid preprocessing token}}

// [cpp.predefined]
#undef defined
// expected-error@-1 {{error: 'defined' cannot be used as a macro name}}

#undef __DATE__
// expected-warning@-1 {{undefining builtin macro}}
// should be turned into an error by default


// [cpp.line]
#line 0 // should diagnose
#line -1
#line 2147483647
#line 2147483648 // should diagnose ?

Metadata

Metadata

Assignees

Labels

c++26clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions