Now that -fabi-version defaults to 0, -Wabi isn't very useful. But for
people interested in compatibility with earlier versions, this patch
allows you to say -Wabi=2 to get any relevant warnings. This patch also
adjusts the compatibility aliases to default to backward compatibility
with -fabi-version=2.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 969f9f501a5a8b7a9498464bf3bef59e685b3895
Author: Jason Merrill
Date: Mon Jun 9 16:41:07 2014 -0400
Support -Wabi warning about backward compatibility.
gcc/c-family/
* c.opt (Wabi=, fabi-compat-version): New.
* c-opts.c (c_common_handle_option): Handle -Wabi=.
(c_common_post_options): Handle flag_abi_compat_version default.
Disallow -fabi-compat-version=1.
* c-common.h (abi_version_crosses): New.
gcc/cp/
* call.c (convert_arg_to_ellipsis): Use abi_version_crosses.
* cvt.c (type_promotes_to): Likewise.
* mangle.c (write_type, write_expression): Likewise.
(write_name, write_template_arg): Likewise.
(mangle_decl): Make alias based on flag_abi_compat_version.
Emit -Wabi warning here.
(finish_mangling_internal): Not here. Drop warn parm.
(finish_mangling_get_identifier, finish_mangling): Adjust.
(mangle_type_string, mangle_special_for_type): Adjust.
(mangle_ctor_vtbl_for_type, mangle_thunk): Adjust.
(mangle_guard_variable, mangle_tls_init_fn): Adjust.
(mangle_tls_wrapper_fn, mangle_ref_init_variable): Adjust.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 83d5dee..6bf4051 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -619,6 +619,13 @@ extern const char *constant_string_class_name;
/* C++ language option variables. */
+/* Return TRUE if one of {flag_abi_version,flag_abi_compat_version} is
+ less than N and the other is at least N, for use by -Wabi. */
+#define abi_version_crosses(N) \
+ (abi_version_at_least(N) \
+ != (flag_abi_compat_version == 0 \
+ || flag_abi_compat_version >= (N)))
+
/* Nonzero means generate separate instantiation control files and
juggle them at link time. */
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 29e9a35..fbbc80e 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -456,6 +456,16 @@ c_common_handle_option (size_t scode, const char *arg, int value,
handle_OPT_d (arg);
break;
+case OPT_Wabi_:
+ warn_abi = true;
+ if (value == 1)
+ {
+ warning (0, "%<-Wabi=1%> is not supported, using =2");
+ value = 2;
+ }
+ flag_abi_compat_version = value;
+ break;
+
case OPT_fcanonical_system_headers:
cpp_opts->canonical_system_headers = value;
break;
@@ -910,6 +920,22 @@ c_common_post_options (const char **pfilename)
if (flag_declone_ctor_dtor == -1)
flag_declone_ctor_dtor = optimize_size;
+ if (flag_abi_compat_version == 1)
+{
+ warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
+ flag_abi_compat_version = 2;
+}
+ else if (flag_abi_compat_version == -1)
+{
+ /* Generate compatibility aliases for ABI v2 (3.4-4.9) by default. */
+ flag_abi_compat_version = (flag_abi_version == 0 ? 2 : 0);
+
+ /* But don't warn about backward compatibility unless explicitly
+ requested with -Wabi=n. */
+ if (flag_abi_version == 0)
+ warn_abi = false;
+}
+
if (cxx_dialect >= cxx11)
{
/* If we're allowing C++0x constructs, don't warn about C++98
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 76e67d7..d2e047f 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -256,6 +256,10 @@ Wabi
C ObjC C++ ObjC++ LTO Var(warn_abi) Warning
Warn about things that will change when compiling with an ABI-compliant compiler
+Wabi=
+C ObjC C++ ObjC++ LTO Joined RejectNegative UInteger Warning
+Warn about things that change between the current -fabi-version and the specified version
+
Wabi-tag
C++ ObjC++ Var(warn_abi_tag) Warning
Warn if a subobject has an abi_tag attribute that the complete object type does not have
@@ -845,6 +849,10 @@ d
C ObjC C++ ObjC++ Joined
; Documented in common.opt. FIXME - what about -dI, -dD, -dN and -dD?
+fabi-compat-version=
+C++ ObjC++ Joined RejectNegative UInteger Var(flag_abi_compat_version) Init(-1)
+The version of the C++ ABI used for -Wabi warnings and link compatibility aliases
+
faccess-control
C++ ObjC++ Var(flag_access_control) Init(1)
Enforce class member access control semantics
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index ac14ce2..44e92fc 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6508,14 +6508,22 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
arg = null_pointer_node;
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
{
- if (SCOPED_ENUM_P (arg_type) && !abi_version_at_least (6))
+ if (SCOPED_ENUM_P (arg_type))
{
- if (complain & tf_warning)
- warning_at (loc, OPT_Wabi, "scoped enu