[Bug c++/67631] brace initialization bug

2021-08-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

Andrew Pinski  changed:

   What|Removed |Added

 CC||tomaszkam at gmail dot com

--- Comment #11 from Andrew Pinski  ---
*** Bug 63999 has been marked as a duplicate of this bug. ***

[Bug c++/67631] brace initialization bug

2016-11-18 Thread howard.hinnant at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #10 from Howard Hinnant  ---
Thanks much Jason!

[Bug c++/67631] brace initialization bug

2016-11-18 Thread jason at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

Jason Merrill  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |6.3

--- Comment #9 from Jason Merrill  ---
Fixed for 6.3.

[Bug c++/67631] brace initialization bug

2016-11-18 Thread jason at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #8 from Jason Merrill  ---
Author: jason
Date: Fri Nov 18 20:27:41 2016
New Revision: 242604

URL: https://gcc.gnu.org/viewcvs?rev=242604&root=gcc&view=rev
Log:
PR c++/67631 - list-init and explicit conversions

* semantics.c (finish_compound_literal): Call digest_init_flags.
* typeck2.c (digest_init_flags): Add complain parm.
(store_init_value): Pass it.

Added:
branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C
Modified:
branches/gcc-6-branch/gcc/cp/ChangeLog
branches/gcc-6-branch/gcc/cp/cp-tree.h
branches/gcc-6-branch/gcc/cp/semantics.c
branches/gcc-6-branch/gcc/cp/typeck2.c

[Bug c++/67631] brace initialization bug

2016-11-18 Thread jason at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #7 from Jason Merrill  ---
Author: jason
Date: Fri Nov 18 20:27:26 2016
New Revision: 242603

URL: https://gcc.gnu.org/viewcvs?rev=242603&root=gcc&view=rev
Log:
PR c++/67631 - list-init and explicit conversions

* semantics.c (finish_compound_literal): Call digest_init_flags.
* typeck2.c (digest_init_flags): Add complain parm.
(store_init_value): Pass it.

Added:
trunk/gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/semantics.c
trunk/gcc/cp/typeck2.c

[Bug c++/67631] brace initialization bug

2016-11-18 Thread jason at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

Jason Merrill  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jason at gcc dot gnu.org

[Bug c++/67631] brace initialization bug

2016-11-14 Thread howard.hinnant at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #6 from Howard Hinnant  ---
Dropping the `explicit` specifier for the operator is an "over my dead body",
sorry.  That would be horrible.  The next best workaround is to "respell" the
explicit int operator() as `as_int() const`.  But then everyone has to remember
library-specific API for the operation instead of Uniform Initialization
Syntax.

[Bug c++/67631] brace initialization bug

2016-11-14 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #5 from Markus Trippelsdorf  ---
A workaround is to drop the "explicit" specifier for the operator.

[Bug c++/67631] brace initialization bug

2016-11-14 Thread howard.hinnant at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #4 from Howard Hinnant  ---
This bug needs some attention because Howard Hinnant's date library is making
it common for people to hit this bug.

The date library:

https://github.com/HowardHinnant/date

This library is sufficiently popular and successful that it has been proposed
to the C++ committee for C++20.

Here is a short HelloWorld demonstrating the problem:

#include "date.h"
#include 

int
main()
{
using namespace date;
using namespace std::chrono;
year_month_day ymd = floor(system_clock::now());
auto y = int{ymd.year()};
std::cout << y << '\n';
}

You can try this out without installing the library at:

http://melpon.org/wandbox/permlink/PodYB3AwdYNFKbMv

Tip of trunk gcc gives:

prog.cc: In function 'int main()':
prog.cc:10:28: error: cannot convert 'date::year' to 'int' in initialization
 auto y = int{ymd.year()};
^

clang prints out the current year (UTC).

Changing the offending line to:

auto y = int(ymd.year());

is a workaround.  But people really like the Uniform Initialization Syntax
(using braces).

[Bug c++/67631] brace initialization bug

2016-11-12 Thread gcc at pauldreik dot se
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

--- Comment #3 from Paul Dreik  ---
This is still present in trunk, rev 242335
g++-trunk (GCC) 7.0.0 20161112 (experimental)

[Bug c++/67631] brace initialization bug

2016-11-12 Thread gcc at pauldreik dot se
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

Paul Dreik  changed:

   What|Removed |Added

 CC||gcc at pauldreik dot se

--- Comment #2 from Paul Dreik  ---
This is still present in 6.2 (as packaged by Debian)

#67631.cpp is the code in Howard Hinnants comment 2015-09-18 20:51:59 UTC
paul@debian-stretch:~$ g++ -std=c++14 67631.cpp 
67631.cpp: In instantiation of 'void test(const U&) [with T = unsigned int; U =
X]':
67631.cpp:34:24:   required from here
67631.cpp:10:7: error: cannot convert 'const X' to 'unsigned int' in
initialization
 t = T{uo};
 ~~^~~
paul@debian-stretch:~$ g++ --version
g++ (Debian 6.2.0-10) 6.2.0 20161027
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[Bug c++/67631] brace initialization bug

2015-09-18 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631

Markus Trippelsdorf  changed:

   What|Removed |Added

   Keywords||rejects-valid
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2015-09-18
 CC||trippels at gcc dot gnu.org
 Ever confirmed|0   |1
  Known to fail||4.9.2, 5.2.1, 6.0

--- Comment #1 from Markus Trippelsdorf  ---
markus@x4 tmp % cat bra.ii
class X
{
public:
  X (int);
  explicit operator unsigned ();
};
unsigned
foo ()
{
  return unsigned{ X (0) };
}
markus@x4 tmp % icpc -Wall -Wextra -c -std=c++14 bra.ii
markus@x4 tmp % clang++ -Wall -Wextra -c -std=c++14 bra.ii
markus@x4 tmp % g++ -Wall -Wextra -c -std=c++14 bra.ii
bra.ii: In function ‘unsigned int foo()’:
bra.ii:10:26: error: cannot convert ‘X’ to ‘unsigned int’ in initialization
   return unsigned{ X (0) };
  ^