Allow disabling gnu extensions
Pass -std=c++14 instead of -std=gnu++14 (or whatever the current default
is) when "gnu_extensions: false" is specified in the blueprints files.
Bug: 32159540
Test: builds
Change-Id: If206228a972129d9574bcf50ddff283b7e7d3fd7
diff --git a/cc/compiler.go b/cc/compiler.go
index 0e65c17..a0068ad 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -84,6 +84,9 @@
// pass -frtti instead of -fno-rtti
Rtti *bool
+ // if set to false, use -std=c++* instead of -std=gnu++*
+ Gnu_extensions *bool
+
Debug, Release struct {
// list of module-specific flags that will be used for C and C++ compiles in debug or
// release builds
@@ -292,6 +295,11 @@
cppStd = config.GccCppStdVersion
}
+ if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false {
+ cStd = gnuToCReplacer.Replace(cStd)
+ cppStd = gnuToCReplacer.Replace(cppStd)
+ }
+
flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...)
flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...)
}
@@ -315,6 +323,8 @@
return flags
}
+var gnuToCReplacer = strings.NewReplacer("gnu", "c")
+
func ndkPathDeps(ctx ModuleContext) android.Paths {
if ctx.sdk() {
// The NDK sysroot timestamp file depends on all the NDK sysroot files