4

The following code snippet builds perfectly fine under Clang 3.4/3.5 (Xcode 5/6), but throws out the error under Visual C++ 14 CTP3:

1>------ Build started: Project: InheritingConstructor, Configuration:
Debug Win32 ------ 1> inheritingconstructor.cpp(60): error C2661:
'D::D': no overloaded function takes 2 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The code does stress the compiler a bit by attempting to inherit a template constructor from the base class, maybe that's where Visual C++ fails again in the competition? Or I am hitting some grey area thus undefined behavior in the standard?

#include "stdafx.h" // comment out this line for Xcode build
#include <iostream>
#include <type_traits>

template <typename X>
struct B
{
    int i;
    B(int i_) : i(i_) {}

    template < typename T, typename = typename std::enable_if<
        std::is_same<T, X>::value >::type >
    B(const T*, const T*) : i(0) {}
};

struct D : B<D>
{
    using B<D>::B; // inherit constructors from B
};

int main(int argc, const char * argv[]) {
    // insert code here...
    D d((D*)nullptr, (D*)nullptr);
    std::cout << "Hello, World!\n";
    return 0;
}
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Dejavu
  • 1,299
  • 14
  • 24
  • Yes, I did test this on gcc 4.8.2, and it compiles fine. I would assume that gcc 4.9.1 would compile this as well. – Dejavu Oct 01 '14 at 19:26
  • The real question here is whether this is a bug in Visual C++'s implementation of inheriting constructors, or a bug in Visual C++'s implementation of SFINAE. – Casey Oct 02 '14 at 00:34
  • 1
    Exactly! I was actually going to edit my original post to mention SFINAE, but was dreaded to introduce more noise. I think one possible cause could be the SFINAE in the context of inheriting constructor is at fault here - in trying to come up with this simple example (from a far more complex code base), I did notice that inheriting constructor and SFINAE alone work as expected independently. – Dejavu Oct 02 '14 at 03:05

1 Answers1

4

There's nothing wrong with your code from a standard compliance perspective.

Inheriting constructors are not implemented in VC++2013 LINK.

However, as this LINK suggests this kind of functionality is implemented since VC++2014 CTP 1.

Digging up a little bit, I found that exactly the same bug with the same example was reported this morning LINK.

Bottom line: This is a VC++2014 bug that it has already been reported.

Niall
  • 30,036
  • 10
  • 99
  • 142
101010
  • 41,839
  • 11
  • 94
  • 168
  • 2
    Yes, that was me who reported the same bug on Microsoft Connect, just thought Stack Overflow might have a better community towards the actual standard rather than being biased with defending it as it's own product. Also, I did specify very clearly on the title that this bug is pertaining to Visual C++ 14 CTP3. – Dejavu Oct 01 '14 at 21:51
  • @Dejavu `Also, I did specify very clearly on the title that this bug is pertaining to Visual C++ 14 CTP3` :[LINK](http://blogs.msdn.com/b/vcblog/archive/2014/08/21/c-11-14-features-in-visual-studio-14-ctp3.aspx) – 101010 Oct 02 '14 at 06:16