Bug 66895 - Array to pointer decay in list initialization
Summary: Array to pointer decay in list initialization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.1.1
: P3 normal
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2015-07-16 06:54 UTC by Stephan Bergmann
Modified: 2015-12-17 10:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-07-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Bergmann 2015-07-16 06:54:32 UTC
> $ cat test.cc
> #include <cstddef>
> #include <initializer_list>
> struct S {
>     template<std::size_t N> S(char const (&)[N]);
> };
> struct T { S s; };
> void f(std::initializer_list<T>);
> void g() { f({{""}}); }

> $ g++ -std=c++11 -fsyntax-only test.cc
> test.cc: In function ‘void g()’:
> test.cc:8:20: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘S’
>  void g() { f({{""}}); }
>                     ^
Comment 1 Patrick Palka 2015-12-17 04:02:19 UTC
Author: ppalka
Date: Thu Dec 17 04:01:47 2015
New Revision: 231736

URL: https://gcc.gnu.org/viewcvs?rev=231736&root=gcc&view=rev
Log:
Fix some blockers of PR c++/24666 (arrays decay to pointers too early)

gcc/cp/ChangeLog:

	PR c++/16333
	PR c++/41426
	PR c++/59878
	PR c++/66895
	* typeck.c (convert_for_initialization): Don't perform an early
	decaying conversion if converting to a class type.

gcc/testsuite/ChangeLog:

	PR c++/16333
	PR c++/41426
	PR c++/59878
	PR c++/66895
	* g++.dg/conversion/pr16333.C: New test.
	* g++.dg/conversion/pr41426.C: New test.
	* g++.dg/conversion/pr59878.C: New test.
	* g++.dg/conversion/pr66895.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/conversion/pr16333.C
    trunk/gcc/testsuite/g++.dg/conversion/pr41426.C
    trunk/gcc/testsuite/g++.dg/conversion/pr59878.C
    trunk/gcc/testsuite/g++.dg/conversion/pr66895.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Paolo Carlini 2015-12-17 10:16:11 UTC
Fixed.