[PATCH] Explicit flag for Conditional Expressions with Omitted Operands

Peter N Lewis peter at stairways.com.au
Tue Aug 13 21:23:08 PDT 2013


This is my first attempt at posting a patch, so please advise me if I have followed the wrong procedure - I hope to do a lot more patches along these lines assuming I can get through the process, so any assistance streamlining the process early on will be helpful.


This patch adds -gnu-conditional-omitted-operand (and -conditional-omitted-operand) flags for the GNU extension allowing the eliding of the middle operand in the ternary conditional expression operator, currently only configurable via the -gnu group.  It is desirable to have a flag for each feature to avoid having to enable all GNU extensions.

The name was selected based on the naming of the GNU feature described as "5.7 Conditionals with Omitted Operands". GCC does not appear to have a matching flag.  The text of the reported error was changed slightly to better match the GNU documentation, and hence agree with the choice of flag name.  A test case was also added.

Files:
test/Sema/conditional-omitted-operand.c
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticParseKinds.td

Index: test/Sema/conditional-omitted-operand.c
===================================================================
--- test/Sema/conditional-omitted-operand.c	(revision 0)
+++ test/Sema/conditional-omitted-operand.c	(revision 0)
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -verify %s -DNONE
+// RUN: %clang_cc1 -verify %s -Wgnu -DEXT
+// RUN: %clang_cc1 -verify %s -Wgnu -Wno-gnu-conditional-omitted-operand -DNONE
+// RUN: %clang_cc1 -verify %s -Wgnu -Wno-conditional-omitted-operand -DNONE
+
+#if NONE
+// expected-no-diagnostics
+#elif EXT
+// expected-warning at 12 {{use of GNU ?: conditional expression extension, omitting middle operand}}
+#endif
+
+static const char* s = 	(const char*)0 ?: "Null";
Index: include/clang/Basic/DiagnosticGroups.td
===================================================================
--- include/clang/Basic/DiagnosticGroups.td	(revision 188139)
+++ include/clang/Basic/DiagnosticGroups.td	(working copy)
@@ -253,6 +253,8 @@
 def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
                                     [TautologicalOutOfRangeCompare]>;
+def GNUConditionalOmittedOperand : DiagGroup<"gnu-conditional-omitted-operand">;
+def ConditionalOmittedOperand : DiagGroup<"conditional-omitted-operand", [GNUConditionalOmittedOperand]>;
 def HeaderHygiene : DiagGroup<"header-hygiene">;
 def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
@@ -524,7 +526,8 @@
 
 // A warning group for warnings about GCC extensions.
 def GNU : DiagGroup<"gnu", [GNUDesignator, VLAExtension,
-                            ZeroLengthArray, GNUStaticFloatInit]>;
+                            ZeroLengthArray, GNUStaticFloatInit,
+                            GNUConditionalOmittedOperand]>;
 // A warning group for warnings about code that clang accepts but gcc doesn't.
 def GccCompat : DiagGroup<"gcc-compat">;
 
Index: include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- include/clang/Basic/DiagnosticParseKinds.td	(revision 188139)
+++ include/clang/Basic/DiagnosticParseKinds.td	(working copy)
@@ -127,7 +127,7 @@
 def ext_gnu_statement_expr : Extension<
   "use of GNU statement expression extension">, InGroup<GNU>;
 def ext_gnu_conditional_expr : Extension<
-  "use of GNU ?: expression extension, eliding middle term">, InGroup<GNU>;
+  "use of GNU ?: conditional expression extension, omitting middle operand">, InGroup<GNUConditionalOmittedOperand>;
 def ext_gnu_empty_initializer : Extension<
   "use of GNU empty initializer extension">, InGroup<GNU>;
 def ext_gnu_array_range : Extension<"use of GNU array range extension">, 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: conditional-omitted-operand-flag.diff
Type: application/octet-stream
Size: 2809 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130814/3ed48687/attachment.obj>
-------------- next part --------------


-- 
Keyboard Maestro 6.1 now out - set web checkboxes & radio buttons, exit from loops, and more.

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.keyboardmaestro.com/>



More information about the cfe-commits mailing list