https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77347

            Bug ID: 77347
           Summary: [6 Regression] Incorrect auto deduction failure in
                    template class member function
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lhyatt at gmail dot com
  Target Milestone: ---

The following valid test case fails to compile starting with gcc 6:

t.cpp
===============================
template<typename = void> auto f() {return 0U;}
template<typename = void>
struct B {
    unsigned g() {
        auto i = 0U, j = f();
        return i+j;
    }
};
auto i = B<>{}.g();
===============================

$ g++ -std=c++14 -c t.cpp
t.cpp: In member function 'unsigned int B< <template-parameter-1-1> >::g()':
t.cpp:5:9: error: inconsistent deduction for 'auto': 'unsigned int' and then
'auto'
         auto i = 0U, j = f();
         ^~~~
===============================

here is output of g++ -v:
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-6.2.0/configure --prefix=/usr/local/gcc-6.2.0
--with-tune=native
Thread model: posix
gcc version 6.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=native' '-march=x86-64'
 /usr/local/gcc-6.2.0/libexec/gcc/x86_64-pc-linux-gnu/6.2.0/cc1plus -quiet -v
-imultiarch x86_64-linux-gnu -D_GNU_SOURCE t.cpp --param l1-cache-size=32
--param l1-cache-line-size=64 --param l2-cache-size=20480 -mtune=sandybridge
-quiet -dumpbase t.cpp -march=x86-64 -auxbase t -version -o /tmp/ccXuYkVf.s
GNU C++14 (GCC) version 6.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 6.2.0, GMP version 5.1.3, MPFR version
3.1.2-p3, MPC version 1.0.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/local/gcc-6.2.0/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/local/gcc-6.2.0/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../include/c++/6.2.0

/usr/local/gcc-6.2.0/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../include/c++/6.2.0/x86_64-pc-linux-gnu

/usr/local/gcc-6.2.0/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../include/c++/6.2.0/backward
 /usr/local/gcc-6.2.0/lib/gcc/x86_64-pc-linux-gnu/6.2.0/include
 /usr/local/include
 /usr/local/gcc-6.2.0/include
 /usr/local/gcc-6.2.0/lib/gcc/x86_64-pc-linux-gnu/6.2.0/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++14 (GCC) version 6.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 6.2.0, GMP version 5.1.3, MPFR version
3.1.2-p3, MPC version 1.0.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0e0cf061fe2036427948ceefe0c946f5
===============================

The issue seems to require that both the global function f and the class B in
which the member function g() lives should be templates.

The issue is still present on the current mainline, it started with r231349:

b34f7e66cb96f137d5283d6285ffa1d333756e52 is the first bad commit
commit b34f7e66cb96f137d5283d6285ffa1d333756e52
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Dec 7 04:34:43 2015 +0000

        PR c++/68597, fix auto9.C and auto-neg1.C with -std=c++1z.

        * decl.c (check_tag_decl): Use ds_type_spec in auto diagnostic.
        * typeck.c (check_return_expr): Check for inconsistent deduction.
        * parser.c (class type_id_in_expr_sentinel): New.
        (cp_parser_primary_expression) [RID_VA_ARG]: Use it.
        (cp_parser_new_expression): Use it.
        (cp_parser_trait_expr): Use it.
        (cp_parser_type_id_1): Complain about auto if in_type_id_in_expr_p.
        (cp_parser_default_type_template_argument): Check for auto.
        (cp_parser_type_id_list): Likewise.
        (cp_parser_simple_type_specifier): Allow auto parms if flag_concepts.
        * pt.c (do_auto_deduction): Handle erroneous type.

    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231349
138bc75d-0d04-0410-961f-82ee72b054a4

Thanks...

-lewis

Reply via email to