public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67910] New: Two autos in a single function confuses the type system
@ 2015-10-09 16:46 guille at cal dot berkeley.edu
  2015-10-09 16:48 ` [Bug c++/67910] " guille at cal dot berkeley.edu
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-09 16:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67910
           Summary: Two autos in a single function confuses the type
                    system
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guille at cal dot berkeley.edu
  Target Milestone: ---

The following code does not compile on 5.2.0:



struct A {};
struct B {};

static auto f(auto b) -> A { return A(); }

int main()
{
    A a = f(B());
    return 0;
}

whereas the following *does* compile:


struct A {};
struct B {};

static auto f(B b) -> A { return A(); }


int main()
{
    __attribute__((unused)) A a = f(B());
    return 0;
}


In the first (failing) case, the type system thinks that 'f' returns the same
type as the first auto *argument*, even though the return type is specified to
be 'A'.


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
@ 2015-10-09 16:48 ` guille at cal dot berkeley.edu
  2015-10-09 16:50 ` guille at cal dot berkeley.edu
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-09 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Guille <guille at cal dot berkeley.edu> ---
Ignore "__attribute__((unused))", it was added by mistake.


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
  2015-10-09 16:48 ` [Bug c++/67910] " guille at cal dot berkeley.edu
@ 2015-10-09 16:50 ` guille at cal dot berkeley.edu
  2015-10-09 16:51 ` guille at cal dot berkeley.edu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-09 16:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Guille <guille at cal dot berkeley.edu> ---


struct A {};
struct B {};

static auto f(auto b) -> A { return A(); } // error: could not convert 'A()'
from 'A' to 'B'

int main()
{
    A a = f(B()); // error: conversion from 'B' to non-scalar type 'A'
requested
    return 0;
}


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
  2015-10-09 16:48 ` [Bug c++/67910] " guille at cal dot berkeley.edu
  2015-10-09 16:50 ` guille at cal dot berkeley.edu
@ 2015-10-09 16:51 ` guille at cal dot berkeley.edu
  2015-10-09 17:17 ` glisse at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-09 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Guille <guille at cal dot berkeley.edu> ---
gcc 5.2.0: -Wall -Wextra -std=c++1y


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
                   ` (2 preceding siblings ...)
  2015-10-09 16:51 ` guille at cal dot berkeley.edu
@ 2015-10-09 17:17 ` glisse at gcc dot gnu.org
  2015-10-09 19:44 ` guille at cal dot berkeley.edu
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-10-09 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |normal

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
This seems to be already fixed on trunk.


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
                   ` (3 preceding siblings ...)
  2015-10-09 17:17 ` glisse at gcc dot gnu.org
@ 2015-10-09 19:44 ` guille at cal dot berkeley.edu
  2015-10-10  5:39 ` guille at cal dot berkeley.edu
  2015-10-10  5:41 ` guille at cal dot berkeley.edu
  6 siblings, 0 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-09 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Guille <guille at cal dot berkeley.edu> ---
(In reply to Marc Glisse from comment #4)
> This seems to be already fixed on trunk.

Just tested on most recent gcc version 5.2.1 20151006 (GCC) and it doesn't
compile:


t.c: In function ‘int main()’:
t.c:10:12: error: conversion from ‘B’ to non-scalar type ‘A’ requested
     A a = f(B());
            ^
t.c: In instantiation of ‘auto:1 f(auto:1) [with auto:1 = B]’:
t.c:10:16:   required from here
t.c:6:39: error: could not convert ‘A()’ from ‘A’ to ‘B’
 static auto f(auto b) -> A { return A(); }
                                       ^
>From gcc-bugs-return-499172-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Oct 09 21:32:42 2015
Return-Path: <gcc-bugs-return-499172-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 3760 invoked by alias); 9 Oct 2015 21:32:42 -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 3720 invoked by uid 48); 9 Oct 2015 21:32:38 -0000
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67913] New: new expression with negative size not diagnosed
Date: Fri, 09 Oct 2015 21:32: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: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: msebor at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
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 target_milestone
Message-ID: <bug-67913-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: 2015-10/txt/msg00727.txt.bz2
Content-length: 1181

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg913

            Bug ID: 67913
           Summary: new expression with negative size not diagnosed
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

A new expression is considered erroneous if the expression in its
noptr-new-declarator is of non-class type and its value before converting to
std::size_t is less than zero.  If the expression is a constant expression, the
program is ill-fomed.  The following program contains two such ill-formed
expressions is not diagnosed by GCC.

void* operator new[] (unsigned long, void *p) { return p; }

void foo (void)
{
    char c;
    new char [-1];
    new (&c) char [-1];
}

Clang issues the following warnings for it:

a.cpp:6:15: warning: array size is negative [-Wbad-array-new-length]
    new char [-1];
              ^~
a.cpp:7:20: warning: array size is negative [-Wbad-array-new-length]
    new (&c) char [-1];
                   ^~
2 warnings generated.


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
                   ` (4 preceding siblings ...)
  2015-10-09 19:44 ` guille at cal dot berkeley.edu
@ 2015-10-10  5:39 ` guille at cal dot berkeley.edu
  2015-10-10  5:41 ` guille at cal dot berkeley.edu
  6 siblings, 0 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-10  5:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Guille <guille at cal dot berkeley.edu> ---
Can confirm it does compile on gcc version 6.0.0 20151004.


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

* [Bug c++/67910] Two autos in a single function confuses the type system
  2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
                   ` (5 preceding siblings ...)
  2015-10-10  5:39 ` guille at cal dot berkeley.edu
@ 2015-10-10  5:41 ` guille at cal dot berkeley.edu
  6 siblings, 0 replies; 8+ messages in thread
From: guille at cal dot berkeley.edu @ 2015-10-10  5:41 UTC (permalink / raw)
  To: gcc-bugs

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

Guille <guille at cal dot berkeley.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Guille <guille at cal dot berkeley.edu> ---
Can confirm it does compile on gcc version 6.0.0 20151004.


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

end of thread, other threads:[~2015-10-10  5:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-09 16:46 [Bug c++/67910] New: Two autos in a single function confuses the type system guille at cal dot berkeley.edu
2015-10-09 16:48 ` [Bug c++/67910] " guille at cal dot berkeley.edu
2015-10-09 16:50 ` guille at cal dot berkeley.edu
2015-10-09 16:51 ` guille at cal dot berkeley.edu
2015-10-09 17:17 ` glisse at gcc dot gnu.org
2015-10-09 19:44 ` guille at cal dot berkeley.edu
2015-10-10  5:39 ` guille at cal dot berkeley.edu
2015-10-10  5:41 ` guille at cal dot berkeley.edu

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