tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This implements N2393.
I am a bit confused by the proposal only taking about adding "true" and "false"
constants but then still using "bool" as a type. I'm not sure if this part of
the patch is 100% correct.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120244
Files:
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Sema/c2x-bool.c
Index: clang/test/Sema/c2x-bool.c
===================================================================
--- /dev/null
+++ clang/test/Sema/c2x-bool.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -fsyntax-only
-verify %s
+
+_Static_assert(_Generic(true, _Bool : 1, default: 0));
+_Static_assert(_Generic(false, _Bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : 1, default: 0));
+_Static_assert(_Generic(false, bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : true, default: false));
+_Static_assert(_Generic(false, bool : true, default: false));
+
+_Static_assert(true == (bool)+1);
+_Static_assert(false == (bool)+0);
+
+
+static void *f = false; // expected-warning {{to null from a constant boolean
expression}}
+static int one = true;
+static int zero = false;
+
+static void do_work() {
+ char *str = "Foo";
+ str[0] = 'f';
+ str[true] = 'f'; // TODO: This should warn(?)
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3245,7 +3245,7 @@
Opts.RenderScript = IK.getLanguage() == Language::RenderScript;
// OpenCL and C++ both have bool, true, false keywords.
- Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
+ Opts.Bool = Opts.OpenCL || Opts.CPlusPlus || Opts.C2x;
// OpenCL has half keyword
Opts.Half = Opts.OpenCL;
Index: clang/test/Sema/c2x-bool.c
===================================================================
--- /dev/null
+++ clang/test/Sema/c2x-bool.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -fsyntax-only -verify %s
+
+_Static_assert(_Generic(true, _Bool : 1, default: 0));
+_Static_assert(_Generic(false, _Bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : 1, default: 0));
+_Static_assert(_Generic(false, bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : true, default: false));
+_Static_assert(_Generic(false, bool : true, default: false));
+
+_Static_assert(true == (bool)+1);
+_Static_assert(false == (bool)+0);
+
+
+static void *f = false; // expected-warning {{to null from a constant boolean expression}}
+static int one = true;
+static int zero = false;
+
+static void do_work() {
+ char *str = "Foo";
+ str[0] = 'f';
+ str[true] = 'f'; // TODO: This should warn(?)
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3245,7 +3245,7 @@
Opts.RenderScript = IK.getLanguage() == Language::RenderScript;
// OpenCL and C++ both have bool, true, false keywords.
- Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
+ Opts.Bool = Opts.OpenCL || Opts.CPlusPlus || Opts.C2x;
// OpenCL has half keyword
Opts.Half = Opts.OpenCL;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits