Fix build with gcc12 Need to skip a bogus flag on gcc 12, reported here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104336 Change-Id: I5b3fd530d20902247d4ea9b5285bf0a389e2fa45 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/16820 Commit-Queue: Brett Wilson <brettw@google.com> Reviewed-by: David Turner <digit@google.com> Reviewed-by: Brett Wilson <brettw@google.com>
diff --git a/build/gen.py b/build/gen.py index 3570746..169427e 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -229,6 +229,17 @@ return 0 +def is_gcc(cxx): + """Return True iff the compiler at `cxx` is GCC based.""" + ret = subprocess.run( + f'{cxx} -dM -E -', + shell=True, + stdin=subprocess.DEVNULL, + text=True, + capture_output=True) + + return ret.returncode == 0 and "#define __GNUC__" in ret.stdout and not "#define __clang__" in ret.stdout + def GenerateLastCommitPosition(host, header): ROOT_TAG = 'initial-commit' describe_output = subprocess.check_output( @@ -480,11 +491,13 @@ '-std=c++20' ]) - # flags not supported by gcc/g++. - if cxx == 'clang++': - cflags.extend(['-Wrange-loop-analysis', '-Wextra-semi-stmt']) - else: + if is_gcc(cxx): cflags.append('-Wno-redundant-move') + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104336 + cflags.append('-Wno-restrict') + # flags not supported by gcc/g++. + else: + cflags.extend(['-Wrange-loop-analysis', '-Wextra-semi-stmt']) if platform.is_linux() or platform.is_mingw() or platform.is_msys(): ldflags.append('-Wl,--as-needed')