public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57573] New: [C++1y] bogus "taking address of temporary" error
@ 2013-06-09 23:37 redi at gcc dot gnu.org
  2014-06-13 21:06 ` [Bug c++/57573] " richard-gccbugzilla at metafoo dot co.uk
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-09 23:37 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 4683 bytes --]

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57573

            Bug ID: 57573
           Summary: [C++1y] bogus "taking address of temporary" error
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

struct A { };
struct B { A a; };

void f(A*) { }

template<class T>
void g()
{
  B b;
  f(&(b.a));
}

This compiles OK with -std=c++98 or -std=c++11 but not -std=c++1y:

$ g++11 f.cc -std=c++1y -c
f.cc: In function ‘void g()’:
f.cc:10:10: error: taking address of temporary [-fpermissive]
   f(&(b.a));
          ^

It also compiles OK if g() is not a template.

This causes an error in <mutex> in C++1y mode:

/home/redi/gcc/4.x/include/c++/4.9.0/mutex: In function ‘void
std::call_once(std::once_flag&, _Callable&&, _Args&& ...)’:
/home/redi/gcc/4.x/include/c++/4.9.0/mutex:786:48: error: lvalue required as
unary ‘&’ operand
       int __e = __gthread_once(&(__once._M_once), &__once_proxy);
                                                ^

I don't know why those parentheses are there in <mutex> so they just can be
removed to fix the problem.
>From gcc-bugs-return-424081-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Jun 09 23:45:21 2013
Return-Path: <gcc-bugs-return-424081-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21541 invoked by alias); 9 Jun 2013 23:45:21 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 21522 invoked by uid 48); 9 Jun 2013 23:45:18 -0000
From: "nszabolcs at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/57574] New: -stdÉ9 inline function incorrectly has external linkage with prior static declaration
Date: Sun, 09 Jun 2013 23:45:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.8.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: nszabolcs at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-57574-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-06/txt/msg00460.txt.bz2
Content-length: 1525

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW574

            Bug ID: 57574
           Summary: -stdÉ9 inline function incorrectly has external
                    linkage with prior static declaration
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nszabolcs at gmail dot com

gcc emits incorrect warning for inline function with internal linkage:

$ cat example.c
static int n;
static inline int f(void);
inline int f(void) {return n;}
int g(){return f();}

$ gcc-4.8 -stdÉ9 -c example.c
example.c:3:28: warning: 'n' is static but used in inline function 'f' which is
not static [enabled by default]
 inline int f(void) {return n;}
                            ^
$ nm example.o
         U f
00000000 T g
00000000 b n

according to C99 6.2.2p4 the linkage of an identifier
is determined by the prior declaration
(internal in this case, inline does not change that)

referencing static objects from an inline definition
only violates the constraint in C99 6.7.4p3 if the
function has external linkage
(so the diagnostic is unjustified)

it seems from the warning that gcc thinks that f
is not static, this can break code:
the inline definition of f does not provide an
external definition and if the compiler choose
not to inline then the code has undefined f symbol
if the compiler thinks f has external linkage
(as demonstrated by nm above)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-02 11:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-09 23:37 [Bug c++/57573] New: [C++1y] bogus "taking address of temporary" error redi at gcc dot gnu.org
2014-06-13 21:06 ` [Bug c++/57573] " richard-gccbugzilla at metafoo dot co.uk
2014-06-14 12:07 ` redi at gcc dot gnu.org
2014-06-26 19:33 ` paolo.carlini at oracle dot com
2014-06-26 19:39 ` paolo.carlini at oracle dot com
2014-06-26 19:39 ` paolo at gcc dot gnu.org
2024-04-02 11:17 ` redi at gcc dot gnu.org

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).