llvm-project/clang/test/Preprocessor/cxx_oper_keyword.cpp
Olivier Goffart 90f981bc5b Keep the IdentifierInfo in the Token for alternative operator keyword
The goal of this commit is to fix clang-format so it does not merge tokens when
using the alternative spelling keywords. (eg: "not foo" should not become "notfoo")

The problem is that Preprocessor::HandleIdentifier used to drop the identifier info
from the token for these keyword. This means the first condition of
TokenAnnotator::spaceRequiredBefore is not met. We could add explicit check for
the spelling in that condition, but I think it is better to keep the IdentifierInfo
and handle the operator keyword explicitly when needed. That actually leads to simpler
code, and probably slightly more efficient as well.

Another side effect of this change is that __identifier(and) will now work as
one would expect, removing a FIXME from the MicrosoftExtensions.cpp test

Differential Revision: https://reviews.llvm.org/D35172

llvm-svn: 308008
2017-07-14 09:23:40 +00:00

44 lines
1.1 KiB
C++

// RUN: %clang_cc1 %s -E -verify -DOPERATOR_NAMES
// RUN: %clang_cc1 %s -E -verify -fno-operator-names
#ifndef OPERATOR_NAMES
//expected-error@+3 {{token is not a valid binary operator in a preprocessor subexpression}}
#endif
// Valid because 'and' is a spelling of '&&'
#if defined foo and bar
#endif
// Not valid in C++ unless -fno-operator-names is passed:
#ifdef OPERATOR_NAMES
//expected-error@+2 {{C++ operator 'and' (aka '&&') used as a macro name}}
#endif
#define and foo
#ifdef OPERATOR_NAMES
//expected-error@+2 {{C++ operator 'xor' (aka '^') used as a macro name}}
#endif
#if defined xor
#endif
// For error recovery we continue as though the identifier was a macro name regardless of -fno-operator-names.
#ifdef OPERATOR_NAMES
//expected-error@+3 {{C++ operator 'and' (aka '&&') used as a macro name}}
#endif
//expected-warning@+2 {{and is defined}}
#ifdef and
#warning and is defined
#endif
#ifdef OPERATOR_NAMES
//expected-error@+2 {{invalid token at start of a preprocessor expression}}
#endif
#if or
#endif
#ifdef OPERATOR_NAMES
//expected-error@+2 {{invalid token at start of a preprocessor expression}}
#endif
#if and_eq
#endif