This is an archive of the discontinued LLVM Phabricator instance.

Suppress -pedantic warnings about GNU extension StmtExpr in glibc's assert macro
Needs ReviewPublic

Authored by sberg on Jul 18 2017, 8:04 AM.

Details

Reviewers
rsmith
Summary

See the mail thread starting at http://lists.llvm.org/pipermail/cfe-dev/2017-July/054666.html "[cfe-dev] -pedantic warnings in system headers?":

The assert.h in glibc 2.25 defines assert as a GNU-extension "statement expression", see https://sourceware.org/git/?p=glibc.git;a=commit;h=e077349ce589466eecd47213db4fae6b80ec18c4 "assert.h: allow gcc to detect assert(a = 1) errors". That caused Clang -pedantic to emit -Wgnu-statement-expression warnings (unlike GCC).

This patch extends the heuristic when to suppress warnings in system headers, to also suppress warnings about extensions used in the body of a function-like macro defined in a system header. (The "function-like" part is there so that the warning from the body of LONG_LONG_MAX in clang/test/CXX/drs/dr4xx.cpp is still emitted.)

I ran into this when trying to build CoinMP (which wants to be built with -pedantic-errors) as part of building LibreOffice master with Clang trunk against Fedora 26 glibc. I'm not sure what the best solution is, though: Either extend the heuristic when to suppress warnings as done here (which has the benefit of aligning the behavior with GCC), or change the CoinMP build system to not insist on -pedantic-error.

Diff Detail

Event Timeline

sberg created this revision.Jul 18 2017, 8:04 AM

Ping - Richard, what'd you reckon? (This came up on another review where -Wzero-as-null-pointer triggered in a system header in libstdc++ I think)

There is a proposed fix for glibc's assert here

https://sourceware.org/ml/libc-alpha/2017-07/msg00227.html

despite that, this patch in general seems useful.

sberg updated this revision to Diff 111634.Aug 18 2017, 1:58 AM

(the original diff had inadvertently lacked full -U999999 context; uploaded a new diff)