Bug 66197 - c++1z generic function wrong type for auto
Summary: c++1z generic function wrong type for auto
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:
Depends on:
Blocks:
 
Reported: 2015-05-19 05:26 UTC by theonetruekenny
Modified: 2015-08-04 17:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-05-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description theonetruekenny 2015-05-19 05:26:07 UTC
https://gcc.gnu.org/ml/gcc-help/2015-05/msg00066.html

#include <iostream>

auto add_1(auto a, auto b) { return a + b;}
auto add_2 = [](auto a, auto b) { return a + b;};

int main()
{
  std::cout
    << "a1: " << add_1(3.5, 4) << "\n"
    << "a2: " << add_1(3, 4.5) << "\n"
    << "a3: " << add_2(3.5, 4) << "\n"
    << "a4: " << add_2(3, 4.5) << "\n";
}

This gives me:
a1: 7.5
a2: 7
a3: 7.5
a4: 7.5

But the expected value for a2 would also be 7.5.
This was with This is with a fedora 22/x86-64 machine.
gcc version 5.1.1 20150422 (Red Hat 5.1.1-1) (GCC)

According to the current spec:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3889.pdf
15 "A generic function is denoted by function declarator having auto
or a concept-name as part of the type-specifier in its
parameter-declaration-clause"

17 "All placeholder types introduced using the same concept-name have
the same invented template parameter."

It would appear that gcc is applying the rule from 17 even in the case of 'auto'.
Comment 1 theonetruekenny 2015-05-19 05:27:30 UTC
This might be another symptom of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64969
Comment 2 Paolo Carlini 2015-08-04 16:16:52 UTC
Indeed, this is also fixed in mainline. I'm adding a testcase and closing the bug.
Comment 3 paolo@gcc.gnu.org 2015-08-04 17:22:37 UTC
Author: paolo
Date: Tue Aug  4 17:22:05 2015
New Revision: 226591

URL: https://gcc.gnu.org/viewcvs?rev=226591&root=gcc&view=rev
Log:
2015-08-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/66197
	* g++.dg/cpp1z/abbrev2.C: New.

2015-08-04  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp1z/static_assert-nomsg.C: Fix DejaGnu directive.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1z/abbrev2.C
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp1z/static_assert-nomsg.C
Comment 4 Paolo Carlini 2015-08-04 17:23:01 UTC
Done.