public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/86491] bogus and unsuppressible warning: 'YYY' has a base 'ZZZ' whose type uses the anonymous namespace
Date: Thu, 30 Jun 2022 08:20:54 +0000	[thread overview]
Message-ID: <bug-86491-4-JDjmK78N3Y@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-86491-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86491

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
In C++98 entities in an anonymous namespace did not have internal linkage, that
was changed for C++11. But they can still cause ODR violations. So the
diagnostic talks about anonymous namespaces because that's what causes the
potential for ODR violations, not linkage. THat was changed for C++11 so that
anonymous namespacs give internal linkage, and things with internal linkage can
now be used in templates, so the existing warning was extended to cover those
cases, but without rewording it.

In C++98 the testcase in comment 7 is simply ill-formed:

tM.C:3:15: error: ‘& d’ is not a valid template argument of type ‘int*’ in
C++98 because ‘d’ does not have external linkage

But if you change it to use an anonymous namespace it's valid in C++98:

# 1 "t1.H"
template < int *_C_OBJ_> struct NT{};
# 2 "tM.C"
namespace { int d; }
struct D : NT<&d> {};

This is valid in C++98 because 'd' doesn't have internal linkage (it's just
different in every translation unit), but it is still a potential ODR
violation, so there's a warning:

tM.C:3:8: warning: ‘D’ has a base ‘NT<(& {anonymous}::d)>’ whose type uses the
anonymous namespace [-Wsubobject-linkage]


Maybe for C++98 it should always say "anonymous namespace" since that's the
only way to trigger the warning, and for C++11 and later it should say internal
linkage, since that is true for names declared 'static' or in an anon
namespace. That seems like an easy change.

  parent reply	other threads:[~2022-06-30  8:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-86491-4@http.gcc.gnu.org/bugzilla/>
2021-11-10  4:57 ` pinskia at gcc dot gnu.org
2021-11-10  8:24 ` redi at gcc dot gnu.org
2021-11-10  9:01 ` redi at gcc dot gnu.org
2022-06-30  4:10 ` pinskia at gcc dot gnu.org
2022-06-30  4:13 ` pinskia at gcc dot gnu.org
2022-06-30  8:20 ` redi at gcc dot gnu.org [this message]
2022-07-04 12:15 ` redi at gcc dot gnu.org
2022-09-12 16:09 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-86491-4-JDjmK78N3Y@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).