[llvm-branch-commits] [clang] 2d2d057 - Add extra test file forgotten in 45d7080.

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 17 00:58:06 PST 2020


Author: Richard Smith
Date: 2020-01-17T09:56:15+01:00
New Revision: 2d2d057ae23036baecb5a2a4a7f929626f46921a

URL: https://github.com/llvm/llvm-project/commit/2d2d057ae23036baecb5a2a4a7f929626f46921a
DIFF: https://github.com/llvm/llvm-project/commit/2d2d057ae23036baecb5a2a4a7f929626f46921a.diff

LOG: Add extra test file forgotten in 45d7080.

(cherry picked from commit b78e8e0d79c47a6698a0abc10a37b8a253cb6064)

Added: 
    clang/test/Parser/explicit-bool.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/clang/test/Parser/explicit-bool.cpp b/clang/test/Parser/explicit-bool.cpp
new file mode 100644
index 000000000000..bdd91dbbafc9
--- /dev/null
+++ b/clang/test/Parser/explicit-bool.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++17 -verify=cxx17 -Wc++2a-compat %s
+// RUN: %clang_cc1 -std=c++2a -verify=cxx2a -Wc++17-compat %s
+
+namespace disambig {
+
+// Cases that are valid in C++17 and before, ill-formed in C++20, and that we
+// should not treat as explicit(bool) as an extension.
+struct A { // cxx2a-note +{{}}
+  constexpr A() {}
+  constexpr operator bool() { return true; }
+
+  constexpr explicit (A)(int); // #1
+  // cxx17-warning@#1 {{will be parsed as explicit(bool)}}
+  // cxx2a-error@#1 +{{}} cxx2a-note@#1 +{{}}
+  // cxx2a-warning@#1 {{incompatible with C++ standards before C++2a}}
+
+  // This is ill-formed (via a DR change), and shouldn't be recognized as a
+  // constructor (the function declarator cannot be parenthesized in a
+  // constructor declaration). But accepting it as an extension seems
+  // reasonable.
+  // FIXME: Produce an ExtWarn for this.
+  constexpr explicit (A(float)); // #1b
+  // cxx17-warning@#1b {{will be parsed as explicit(bool)}}
+  // cxx2a-error@#1b +{{}}
+  // cxx2a-warning@#1b {{incompatible with C++ standards before C++2a}}
+
+  explicit (operator int)(); // #2
+  // cxx17-warning@#2 {{will be parsed as explicit(bool)}}
+  // cxx2a-error@#2 +{{}}
+  // cxx2a-warning@#2 {{incompatible with C++ standards before C++2a}}
+
+  explicit (A::operator float)(); // #2b
+  // cxx17-warning@#2b {{will be parsed as explicit(bool)}}
+  // cxx17-error@#2b {{extra qualification on member}}
+  // cxx2a-error@#2b +{{}}
+  // cxx2a-warning@#2b {{incompatible with C++ standards before C++2a}}
+};
+
+constexpr bool operator+(A) { return true; }
+
+constexpr bool C = false;
+
+// Cases that should (ideally) be disambiguated as explicit(bool) in earlier
+// language modes as an extension.
+struct B {
+  // Looks like a constructor, but not the constructor of B.
+  explicit (A()) B(); // #3
+  // cxx17-warning@#3 {{C++2a extension}}
+  // cxx2a-warning@#3 {{incompatible with C++ standards before C++2a}}
+
+  // Looks like a 'constructor' of C. Actually a constructor of B.
+  explicit (C)(B)(A); // #4
+  // cxx17-warning@#4 {{C++2a extension}}
+  // cxx2a-warning@#4 {{incompatible with C++ standards before C++2a}}
+
+  explicit (operator+(A())) operator int(); // #5
+  // cxx17-error@#5 {{requires a type specifier}} cxx17-error@#5 {{expected ';'}}
+  // cxx17-warning@#5 {{will be parsed as explicit(bool)}}
+  // cxx2a-warning@#5 {{incompatible with C++ standards before C++2a}}
+};
+
+}


        


More information about the llvm-branch-commits mailing list