This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCHv3, resent] Add a warning for suspicious use of conditional expressions in boolean context


On 09/21/16 21:03, Jason Merrill wrote:
> On Wed, Sep 21, 2016 at 11:43 AM, Bernd Edlinger
> <bernd.edlinger@hotmail.de> wrote:
>> Yes.  I think that goes in the right direction,
>> but it does not work yet.
>>
>> #define XXX (a ? 2 : 3)
>>
>> if (XXX) // prints a warning, but it should not.
>
> Indeed, that was too simplistic.  This patch adds a
> from_macro_definition_at test that ought to do what you want:
>

I tried something similar, which seems to work:

--- input.h	(Revision 240313)
+++ input.h	(Arbeitskopie)
@@ -73,10 +73,19 @@
     header, but expanded in a non-system file.  */
  #define in_system_header_at(LOC) \
    (linemap_location_in_system_header_p (line_table, LOC))
-/* Return a positive value if LOCATION is the locus of a token that
-   comes from a macro expansion, O otherwise.  */
-#define from_macro_expansion_at(LOC) \
-  ((linemap_location_from_macro_expansion_p (line_table, LOC)))
+/* Return TRUE if LOCATION is the locus of a token that
+   comes from a macro expansion, FALSE otherwise.  */
+static inline bool
+from_macro_expansion_at (location_t loc)
+{
+  /* Resolve to the spelling location so we return false for arguments to a
+     macro.  */
+  return linemap_location_from_macro_expansion_p (line_table, loc)
+	 && linemap_resolve_location (line_table, loc,
+				      LRK_MACRO_DEFINITION_LOCATION, NULL)
+	    == linemap_resolve_location (line_table, loc,
+					 LRK_SPELLING_LOCATION, NULL);
+}

  static inline location_t
  get_pure_location (location_t loc)


I will try your patch now, and see if it works for me.


Thanks
Bernd.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]