none
VS2015 CTP5 "error C2440: '<function-style-cast>': cannot convert from 'initializer-list' to 'Foo', note: Source or target has incomplete type" RRS feed

  • Question

  • The following test program is rejected by VS2015 CTP5, of course, but I don't really understand the error message!

    class Foo;
    
    int main(void) 
    {
    	Foo();
    }
    

    VS2015 CTP5 produces the following output:

    Microsoft (R) C/C++ Optimizing Compiler Version 19.00.22512 for x86
    Copyright (C) Microsoft Corporation.  All rights reserved.

    MySource.cpp(5): error C2440: '<function-style-cast>': cannot convert from 'initializer-list' to 'Foo'
    MySource.cpp(5): note: Source or target has incomplete type

    A similar output is produced by compiler version 19.00.22318 at http://webcompiler.cloudapp.net

    I don't see any function-style-cast or initializer-list in the source code above here. Is this a compiler bug? If so, should it still be reported to https://connect.microsoft.com/VisualStudio ? 

    Saturday, February 7, 2015 10:46 PM

Answers

All replies

  • I can reproduce this in VS 2015 CTP.

    For VS2013, ther output error is:

    error C2514: 'Foo' : class has no constructors

    If I change Foo(); to Foo({});

    class Foo;
    
    int main(void)
    {
    	Foo({});
    }

    The output error is :

    error C2440: '<function-style-cast>' : cannot convert from 'initializer-list' to 'Foo'

    For me , this behavior in VS 2013 as I expected. I cannot tell the issue whether it is a bug or a by designer issue. You can try to submit to connect and this will help MS to improve VS 2015 before it is released.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 9, 2015 8:55 AM
    Moderator
  • Thank you for your helpful reply, Shu Hu.  Indeed, the error message would have been appropriate if Foo() would be changed to Foo({}).

    I just submitted the compiler bug:

    [C++] Incorrect error message, "error C2440: '<function-style-cast>': cannot convert from 'initializer-list' to 'Foo', note: Source or target has incomplete type"

    https://connect.microsoft.com/VisualStudio/feedbackdetail/view/1121519

    Please check!

    Monday, February 9, 2015 10:02 AM