https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91961

            Bug ID: 91961
           Summary: __has_attribute expands macro argument
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While testing my patch for pr66970 against Clang I noticed a difference in how
the two compilers deal with macro arguments to the __has_attribute (and
__has_builtin) operators: Clang doesn't expand macros while GCC does.  I can
see arguments for either approach so this is just to record the difference and,
ultimately, the decision to either stick with the GCC behavior that's been in
place presumably since 2014 (when r217292 added __has_attribute) or change it
to follow what Clang does, and the rationale for it.

$ (set -x; cat b.c; clang -S b.c; gcc -S -Wall b.c)
+ cat b.c
#define NORETURN noreturn

#if !__has_attribute (noreturn)
#  error "__has_attribute (noreturn) failed"
#endif

#if !__has_attribute (NORETURN)
#  error "__has_attribute (NORETURN) failed"
#endif

+ clang -S b.c
b.c:8:4: error: "__has_attribute (NORETURN) failed"
#  error "__has_attribute (NORETURN) failed"
   ^
1 error generated.
+ gcc -S -Wall b.c
$

Reply via email to