Bug 80873 - ICE in tsubst_copy when trying to use an overloaded function without a definition in a lambda
Summary: ICE in tsubst_copy when trying to use an overloaded function without a defini...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1.1
: P3 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, ice-on-valid-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2017-05-24 10:31 UTC by Morris Hafner
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 6.3.0
Known to fail: 7.1.0, 7.1.1, 8.0
Last reconfirmed: 2017-10-05 00:00:00


Attachments
Minimal example code (147 bytes, text/plain)
2017-05-24 10:31 UTC, Morris Hafner
Details
Minimal example code (valid) (145 bytes, text/plain)
2017-05-24 13:43 UTC, Morris Hafner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Morris Hafner 2017-05-24 10:31:24 UTC
Created attachment 41411 [details]
Minimal example code

The following invalid code causes an ICE:

struct S {};

auto overloaded(S &);

template <typename T>
int overloaded(T &) {
    return 0;
}

template <typename T>
auto returns_lambda(T &param) {
	return [&] {
		overloaded(param);
	};
}

int main() {
	S s;
	returns_lambda(s);
}

On Wandbox:
https://wandbox.org/permlink/bU36doHcn0MoXWrK

Only gcc versions 7.1 and up seem to be affected. No compiler flags are required.
Comment 1 Morris Hafner 2017-05-24 13:41:49 UTC
I managed to create an example that is a valid program:

struct Buffer {};

auto parse(Buffer b);
template <typename T> void parse(T target);

template <typename T>
auto field(T target) {
	return [&] {
		parse(target);
	};
}

template <typename T>
void parse(T target) {}

auto parse(Buffer b) {
	field(0);
}

int main() {
}
Comment 2 Morris Hafner 2017-05-24 13:43:03 UTC
Created attachment 41413 [details]
Minimal example code (valid)
Comment 3 paolo@gcc.gnu.org 2017-10-13 16:50:44 UTC
Author: paolo
Date: Fri Oct 13 16:50:13 2017
New Revision: 253733

URL: https://gcc.gnu.org/viewcvs?rev=253733&root=gcc&view=rev
Log:
2017-10-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/80873
	* g++.dg/cpp1y/auto-fn41.C: New.
	* g++.dg/cpp1y/auto-fn42.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/auto-fn41.C
    trunk/gcc/testsuite/g++.dg/cpp1y/auto-fn42.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2017-10-13 16:51:27 UTC
Fixed for 7.3.0.