Author: Reid Kleckner Date: 2021-08-25T14:41:26-07:00 New Revision: db3d029fbe09925ea42a3279b1abb244fa547cff
URL: https://github.com/llvm/llvm-project/commit/db3d029fbe09925ea42a3279b1abb244fa547cff DIFF: https://github.com/llvm/llvm-project/commit/db3d029fbe09925ea42a3279b1abb244fa547cff.diff LOG: Effectively revert 33c3d8a916c / D33782 This change would treat the token `or` in system headers as an identifier, and elsewhere as an operator. As reported in llvm.org/pr42427, many users classify their third party library headers as "system" headers to suppress warnings. There's no clean way to separate Windows SDK headers from user headers. Clang is still able to parse old Windows SDK headers if C++ operator names are disabled. Traditionally this was controlled by `-fno-operator-names`, but is now also enabled with `/permissive` since D103773. This change will prevent `clang-cl` from parsing <query.h> from the Windows SDK out of the box, but there are multiple ways to work around that: - Pass `/clang:-fno-operator-names` - Pass `/permissive` - Pass `-DQUERY_H_RESTRICTION_PERMISSIVE` In all of these modes, the operator names will consistently be available or not available, instead of depending on whether the code is in a system header. I added a release note for this, since it may break straightforward users of the Windows SDK. Fixes PR42427 Differential Revision: https://reviews.llvm.org/D108720 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Lex/Preprocessor.cpp Removed: clang/test/Headers/ms-cppoperkey.cpp clang/test/Headers/ms-cppoperkey1.cpp clang/test/Headers/ms-cppoperkey2.cpp ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4ed7543a2b86..8bae1ed29eeb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -97,6 +97,12 @@ Attribute Changes in Clang Windows Support --------------- +- An MSVC compatibility workaround for C++ operator names was removed. As a + result, the ``<query.h>`` Windows SDK header may not compile out of the box. + Users should use a recent SDK and pass ``-DQUERY_H_RESTRICTION_PERMISSIVE`` + or pass ``/permissive`` to disable C++ operator names altogether. See + `PR42427 <https://llvm.org/pr42427>` for more info. + C Language Changes in Clang --------------------------- diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index d79637a68a8b..97615d89cefc 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -723,11 +723,7 @@ IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const { // is cleaned to tok::identifier "B". After cleaning the token's length is // still 3 and the SourceLocation refers to the location of the backslash. Identifier.setIdentifierInfo(II); - if (getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() && - getSourceManager().isInSystemHeader(Identifier.getLocation())) - Identifier.setKind(tok::identifier); - else - Identifier.setKind(II->getTokenID()); + Identifier.setKind(II->getTokenID()); return II; } diff --git a/clang/test/Headers/ms-cppoperkey.cpp b/clang/test/Headers/ms-cppoperkey.cpp deleted file mode 100644 index ca56ee17bcb1..000000000000 --- a/clang/test/Headers/ms-cppoperkey.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// RUN: %clang_cc1 \ -// RUN: -fms-compatibility -x c++-cpp-output \ -// RUN: -ffreestanding -fsyntax-only -Werror \ -// RUN: %s -verify -// expected-no-diagnostics -# 1 "t.cpp" -# 1 "query.h" 1 3 -// MS header <query.h> uses operator keyword as field name. -// Compile without syntax errors. -struct tagRESTRICTION - { - union _URes - { - int or; // Note use of cpp operator token - } res; - }; diff --git a/clang/test/Headers/ms-cppoperkey1.cpp b/clang/test/Headers/ms-cppoperkey1.cpp deleted file mode 100644 index c03efc9dacde..000000000000 --- a/clang/test/Headers/ms-cppoperkey1.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %clang_cc1 \ -// RUN: -fms-compatibility -x c++-cpp-output \ -// RUN: -ffreestanding -fsyntax-only -Werror \ -// RUN: %s -verify - - -# 1 "t.cpp" -# 1 "query.h" 1 3 4 -// MS header <query.h> uses operator keyword as field name. -// Compile without syntax errors. -struct tagRESTRICTION - { - union _URes - { - int or; // Note use of cpp operator token - } res; - }; - ; - -int aa ( int x) -{ - // In system header code, treat operator keyword as identifier. - if ( // expected-note{{to match this '('}} - x>1 or x<0) return 1; // expected-error{{expected ')'}} - else return 0; -} - diff --git a/clang/test/Headers/ms-cppoperkey2.cpp b/clang/test/Headers/ms-cppoperkey2.cpp deleted file mode 100644 index 2afed36b7446..000000000000 --- a/clang/test/Headers/ms-cppoperkey2.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-pc-win32 -fms-compatibility \ -// RUN: -ffreestanding -fsyntax-only -Werror %s -verify -// RUN: %clang_cc1 \ -// RUN: -ffreestanding -fsyntax-only -Werror %s -verify -// expected-no-diagnostics -int bb ( int x) -{ - // In user code, treat operator keyword as operator keyword. - if ( x>1 or x<0) return 1; - else return 0; -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits