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

            Bug ID: 61937
           Summary: Misleading errors due to constructor template deducing
                    argument as void
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

template<typename T, typename U = void>
  struct trait;

template<typename T>
  struct trait<T, T>
  {
  using type = T;
  };

template<typename T>
  struct trait<T, void>
  {
    using type = T;
  };

struct S {
  template<typename T, typename U = typename trait<T>::type>
    S(const T&) { }
};

void f() { }

S s = f();

Compiling with -std=c++11 gives four errors:

void.cc: In substitution of ‘template<class T, class U> S::S(const T&) [with T
= void; U = <missing>]’:
void.cc:23:9:   required from here
void.cc:17:24: error: ambiguous class template instantiation for ‘struct
trait<void, void>’
   template<typename T, typename U = typename trait<T>::type>
                        ^
void.cc:5:10: error: candidates are: struct trait<T, T>
   struct trait<T, T>
          ^
void.cc:11:10: error:                 struct trait<T, void>
   struct trait<T, void>
          ^
void.cc:23:9: error: conversion from ‘void’ to non-scalar type ‘S’ requested
 S s = f();
         ^

Only the last one is relevant and useful, the others are just confusing.

The first three errors are due to instantiating the constructor template with T
= void but that doesn't make much sense. It implies the function f() returns an
object of type void, rather than returning nothing.

Reply via email to