Commit af5475b8 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Continue using -std=gnu* on gcc builds

"Some compilers offer an extension that allows ## to appear after a comma and
before __VA_ARGS__, in which case the ## does nothing when the variable
arguments are present, but removes the comma when the variable arguments are not
present: this makes it possible to define macros such as fprintf (stderr,
format, ##__VA_ARGS__)" [1]

This is problematic for Chromium since ##__VA_ARGS__ doesn't swallow the
preceding comma in standards-compliant mode on gcc [2].

Since we use this feature in Chromium (eg base), switch the gcc config back to
-std=gnu*.  C++20 adds a standards-compliant macro called __VA_OPT__ that we can
use to replicate the behavior of ##__VA_ARGS__ when we eventually enable it.

[1] https://en.cppreference.com/w/cpp/preprocessor/replace
[2] https://github.com/gcc-mirror/gcc/blob/6d6279f88e9678c458bc22ea3be03e73f462f9e7/libcpp/macro.c#L1167

R=thakis

Change-Id: I6c0f3e64ad21b6270822011733d44098537b8f02
Reviewed-on: https://chromium-review.googlesource.com/1181657Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarSergiy Byelozyorov <sergiyb@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584562}
parent bdd22b54
...@@ -550,22 +550,34 @@ config("compiler") { ...@@ -550,22 +550,34 @@ config("compiler") {
cxx11_override = use_cxx11 cxx11_override = use_cxx11
} }
# Since we build with -std=c* and not -std=gnu*, _GNU_SOURCE will not be if (is_clang) {
# defined by the compiler. However, lots of code relies on the non-standard standard_prefix = "c"
# features that _GNU_SOURCE enables, so define it manually.
defines += [ "_GNU_SOURCE" ]
cflags_c += [ "-std=c11" ] # Since we build with -std=c* and not -std=gnu*, _GNU_SOURCE will not be
# defined by the compiler. However, lots of code relies on the
# non-standard features that _GNU_SOURCE enables, so define it manually.
defines += [ "_GNU_SOURCE" ]
if (is_nacl) {
# Undefine __STRICT_ANSI__ to get non-standard features which would
# otherwise not be enabled by NaCl's sysroots.
cflags += [ "-U__STRICT_ANSI__" ]
}
} else {
# Gcc does not support ##__VA_ARGS__ when in standards-conforming mode,
# but we use this feature in several places in Chromium.
# TODO(thomasanderson): Replace usages of ##__VA_ARGS__ with the
# standard-compliant __VA_OPT__ added by C++20, and switch the gcc build
# to -std=c*.
standard_prefix = "gnu"
}
cflags_c += [ "-std=${standard_prefix}11" ]
if (cxx11_override) { if (cxx11_override) {
# Override Chromium's default for projects that wish to stay on C++11. # Override Chromium's default for projects that wish to stay on C++11.
cflags_cc += [ "-std=c++11" ] cflags_cc += [ "-std=${standard_prefix}++11" ]
} else { } else {
cflags_cc += [ "-std=c++14" ] cflags_cc += [ "-std=${standard_prefix}++14" ]
}
if (is_nacl) {
# Undefine __STRICT_ANSI__ to get non-standard features which would
# otherwise not be enabled by NaCl's sysroots.
cflags += [ "-U__STRICT_ANSI__" ]
} }
} else if (!is_win && !is_nacl) { } else if (!is_win && !is_nacl) {
if (target_os == "android") { if (target_os == "android") {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment