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

* [Bug c++/57573] [C++1y] bogus "taking address of temporary" error
  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 ` richard-gccbugzilla at metafoo dot co.uk
  2014-06-14 12:07 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2014-06-13 21:06 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Smith <richard-gccbugzilla at metafoo dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |richard-gccbugzilla@metafoo
                   |                            |.co.uk

--- Comment #1 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
This seems to work with GCC trunk.


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

* [Bug c++/57573] [C++1y] bogus "taking address of temporary" error
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-06-14 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And with the released 4.9.0 too. We should add the testcase and close it.


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

* [Bug c++/57573] [C++1y] bogus "taking address of temporary" error
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-26 19:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Agreed, I'm taking care of that.


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

* [Bug c++/57573] [C++1y] bogus "taking address of temporary" error
  2013-06-09 23:37 [Bug c++/57573] New: [C++1y] bogus "taking address of temporary" error redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-26 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
      Known to work|                            |4.10.0, 4.9.0
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.9.0

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

* [Bug c++/57573] [C++1y] bogus "taking address of temporary" error
  2013-06-09 23:37 [Bug c++/57573] New: [C++1y] bogus "taking address of temporary" error redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-06-26 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Thu Jun 26 19:38:36 2014
New Revision: 212052

URL: https://gcc.gnu.org/viewcvs?rev=212052&root=gcc&view=rev
Log:
2014-06-26  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/57573
    * g++.dg/template/pr57573.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/template/pr57573.C
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/57573] [C++1y] bogus "taking address of temporary" error
  2013-06-09 23:37 [Bug c++/57573] New: [C++1y] bogus "taking address of temporary" error redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-06-26 19:39 ` paolo at gcc dot gnu.org
@ 2024-04-02 11:17 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-02 11:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=60409
      Known to work|4.10.0                      |5.0

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For the record, it started to fail with:

commit 10c6dc8e3932d33c8e47e6706885d2412b29c069 [r0-122521-g10c6dc8e3932d3]
Author: Jason Merrill
Date:   Fri Mar 29 19:51:36 2013

    cp-tree.h (AUTO_IS_DECLTYPE): New.

            N3582
            * cp-tree.h (AUTO_IS_DECLTYPE): New.
            * parser.c (cp_parser_decltype): Handle decltype(auto).
            (cp_parser_type_id_1): Allow auto without a late-specified
            return in C++1y.
            (cp_parser_primary_expression): Use the return value of
            finish_parenthesized_expr.
            (cp_parser_transaction_expression): Likewise.
            * semantics.c (force_paren_expr): New.
            (finish_parenthesized_expr): Use it.
            * call.c (build_conditional_expr_1): Likewise.
            * pt.c (do_auto_deduction): Handle decltype(auto).
            (tsubst_copy): Handle PAREN_EXPR.
            (tsubst_copy_and_build): Likewise.
            * error.c (dump_expr): Handle PAREN_EXPR.
            * cxx-pretty-print.c (pp_cxx_expression): Likewise.
            * mangle.c (write_expression): Ignore PAREN_EXPR.

            * parser.c (cp_parser_decltype_expr): Split out...
            (cp_parser_decltype): ...from here.

    From-SVN: r197248

That commit also caused an ICE, and then this bug and the ICE were both fixed
by:

commit f9b381b8eb56252e302b88ea4fe89beffc33cf80 [r0-128726-gf9b381b8eb5625]
Author: Jason Merrill
Date:   Wed Mar 5 19:25:37 2014

    re PR c++/60409 ([c++1y] ICE on valid with template function)

            PR c++/60409
            * semantics.c (force_paren_expr): Only add a PAREN_EXPR to a
            dependent expression.

    From-SVN: r208352

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