Bug 65775 - Late-specified return type bypasses return type checks (qualified, function, array)
Summary: Late-specified return type bypasses return type checks (qualified, function, ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
: 38797 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-04-15 16:07 UTC by Ed Catmur
Modified: 2018-04-19 15:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-04-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Catmur 2015-04-15 16:07:04 UTC
If a function declaration has a late-specified return type the usual checks on return types are bypassed:

using Qi = int const volatile;
Qi q1();           // warning: type qualifiers ignored on function return type
auto q2() -> Qi;   // no warning

using Fi = int();
Fi f1();           // error: 'f1' declared as function returning a function
auto f2() -> Fi;   // error: function return type cannot be function

using Ai = int[5];
Ai a1();           // error: 'a1' declared as function returning an array
auto a2() -> Ai;   // no error

Qualifiers: previously filed as bug 38797 RESOLVED INVALID; I don't entirely agree with the resolution but am willing to let it stand.

Function: shows an inconsistent and less informative error, issuing later from gcc/tree.c build_function_type().

Array: the function returning a (prvalue) array is allowed to be declared and can even be defined, called and the result subscripted, though not at -Werror=pedantic: http://stackoverflow.com/q/29628571/567292

I think it should be possible to move at least the function and array return checks to after late-specified return type evaluation.
Comment 1 Ed Catmur 2015-04-15 16:07:52 UTC
Credit to FISOCPP (http://stackoverflow.com/q/29628571/567292) for finding this bug.
Comment 2 Paolo Carlini 2017-06-23 12:38:31 UTC
Mine.
Comment 3 paolo@gcc.gnu.org 2017-07-03 18:11:24 UTC
Author: paolo
Date: Mon Jul  3 18:10:52 2017
New Revision: 249935

URL: https://gcc.gnu.org/viewcvs?rev=249935&root=gcc&view=rev
Log:
/cp
2017-07-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65775
	* decl.c (grokdeclarator): Move checks on function return type after
	the splice_late_return_type call; if declspecs->locations[ds_type_spec]
	is UNKNOWN_LOCATION fall back to input_location.

/testsuite
2017-07-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65775
	* g++.dg/cpp0x/trailing14.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/trailing14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2017-07-03 18:12:39 UTC
Fixed.
Comment 5 Volker Reichelt 2017-07-09 22:12:03 UTC
*** Bug 38797 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Wakely 2018-04-19 15:29:35 UTC
Author: redi
Date: Thu Apr 19 15:29:03 2018
New Revision: 259499

URL: https://gcc.gnu.org/viewcvs?rev=259499&root=gcc&view=rev
Log:
PR c++/85464 - missing location for -Wignored-qualifiers diagnostic

The fix for PR c++/69733 caused a regression for conversion operators
with redundant cv-qualifiers, changing an incorrect location to an
unknown location. This restores it to the incorrect location (as was
already done on trunk by the fix for PR c++/65775).

gcc/cp:

	PR c++/85464 - missing location for -Wignored-qualifiers diagnostic
	* decl.c (grokdeclarator): If declspecs->locations[ds_type_spec]
	is UNKNOWN_LOCATION fall back to input_location.

gcc/testsuite:

	PR c++/85464 - missing location for -Wignored-qualifiers diagnostic
	* g++.dg/diagnostic/pr85464.C: New.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/diagnostic/pr85464.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/decl.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog