Bug 59879 - arrays in return statements or default arguments decay too early
Summary: arrays in return statements or default arguments decay too early
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 24666
  Show dependency treegraph
 
Reported: 2014-01-19 13:03 UTC by Stephan Tolksdorf
Modified: 2015-12-17 14:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-03-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Tolksdorf 2014-01-19 13:03:17 UTC
g++ seems to decay arrays in return statements or default arguments too early. 

The following sample fails to compile with 4.8.2 and the current GIT master version of gcc but compiles cleanly in clang:

--
struct Test {
  template <int N>
  Test(const char (&array)[N]) {}
};

Test test() {
  return "test";
}

void test2(Test arg = "test") {}

int main() {
  test();
  test2();
}
--

g++ test.cpp
test.cpp: In function ‘Test test()’:
test.cpp:8:10: error: could not convert ‘(const char*)"test"’ from ‘const char*’ to ‘Test’
   return "test";
          ^
test.cpp: In function ‘int main()’:
test.cpp:15:9: error: could not convert ‘(const char*)"test"’ from ‘const char*’ to ‘Test’
   test2();
         ^
Comment 1 Patrick Palka 2015-12-17 13:30:46 UTC
Author: ppalka
Date: Thu Dec 17 13:30:04 2015
New Revision: 231755

URL: https://gcc.gnu.org/viewcvs?rev=231755&root=gcc&view=rev
Log:
Fix wrong PR references

PR c++/59878 -> PR c++/59879


Added:
    trunk/gcc/testsuite/g++.dg/conversion/pr59879.C
Removed:
    trunk/gcc/testsuite/g++.dg/conversion/pr59878.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/testsuite/ChangeLog
Comment 2 Paolo Carlini 2015-12-17 14:44:49 UTC
Fixed in r231736.