-
October 19th, 2024, 05:11 AM
#1
Should this be buildable with VC++17 ?
Admittedly I haven't given details for PBD::Signal but basically it's a cross-platform class for generating and handling signals.
Anyway... the following code compiles with most C++17 compilers, including (on Windows) Clang
But MSVC tells me illegal use of type void
Code:
#include "pbd/signals.h"
class Destructible {
public:
virtual ~Destructible () { Destroyed(); }
PBD::Signal<void()> Destroyed;
};
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 20th, 2024, 03:52 AM
#2
Re: Should this be buildable with VC++17 ?
I'm not sure if this is relevant but I've noticed that other source files use std::function<void()> and in that context, MSVC seems happy to accept void() - though not in this context...
[Edit...] after some further testing, I've made an important discovery...
Despite the error message here it's not the declaration of void() that's causing the problem. It's something about it's usage. i.e. if I change my class to this, the compiler's then happy:-
Code:
#include "pbd/signals.h"
class Destructible {
public:
// virtual ~Destructible () { Destroyed(); }
PBD::Signal<void()> Destroyed;
};
and this also builds with MSVC:-
Code:
#include "pbd/signals.h"
class Destructible {
public:
virtual ~Destructible () { Destroyed(); }
PBD::Signal<void()> Destroyed();
};
So I'll need to get hold of the guy who changed it. It's looking like it might be a problem at our end
Last edited by John E; October 20th, 2024 at 09:22 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 22nd, 2024, 03:55 AM
#3
Re: Should this be buildable with VC++17 ?
Still can't get hold of the original dev but I've noticed something else I don't understand... it's a template defined like this:-
Code:
template <typename Combiner, typename R, typename... A>
typename std::conditional_t<std::is_void_v<R>, R, typename Combiner::result_type>
SignalWithCombiner<Combiner, R(A...)>::operator() (A... a)
{
// main body of template code
}
Regarding the bold line, am I misunderstanding this..? To me, it looks like the return type from this template function will be different, depending on whether R is deemed to be void or non-void (i.e. it won't just return a different value, but a different type
I'd be surprised if MSVC supports that... or did I misunderstand?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 25th, 2024, 03:05 AM
#4
Re: Should this be buildable with VC++17 ?
In the hope this might turn out to be an issue with VS2019, if there's someone here building with a later version, could they try this code and just let me know if it'll compile?
Code:
#include <list>
#include <optional>
#include <functional>
#include <iostream>
class SignalBase
{
public:
SignalBase ();
};
template<typename R>
class OptionalLastValue
{
public:
typedef std::optional<R> result_type;
template <typename Iter>
result_type operator() (Iter first, Iter last) const {
result_type r;
while (first != last) {
r = *first;
++first;
}
return r;
}
};
template <typename Combiner, typename _Signature>
class SignalWithCombiner;
template <typename Combiner, typename R, typename... A>
class SignalWithCombiner<Combiner, R(A...)> : public SignalBase
{
public:
typename std::conditional_t<std::is_void_v<R>, R, typename Combiner::result_type>
operator() (A... a);
};
template <typename Combiner, typename R, typename... A>
typename std::conditional_t<std::is_void_v<R>, R, typename Combiner::result_type>
SignalWithCombiner<Combiner, R(A...)>::operator() (A... a)
{
if constexpr (std::is_void_v<R>) {
} else {
std::list<R> r;
// Populate the list...
Combiner c;
return c (r.begin(), r.end());
}
}
template <typename R>
using DefaultCombiner = OptionalLastValue<R>;
template <typename _Signature>
class Signal;
template <typename R, typename... A>
class Signal<R(A...)> : public SignalWithCombiner<DefaultCombiner<R>, R(A...)> {};
// Below is the problematic code I initially reported...
class Destructible {
public:
virtual ~Destructible () { Destroyed(); }
Signal<void()> Destroyed;
};
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 25th, 2024, 03:23 AM
#5
Re: Should this be buildable with VC++17 ?
I've tried it with VS2022 as C++23. No, it doesn't compile. It complains on the list<R> statement that you cannot create a reference to 'void'
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 25th, 2024, 04:13 AM
#6
Re: Should this be buildable with VC++17 ?
Ooh that's quite interesting 2kaud. Which error number are you seeing? I see error C2182 but I see it at the call to Destroyed();
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 25th, 2024, 05:55 AM
#7
Re: Should this be buildable with VC++17 ?
The full errors are:
Code:
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(772): error C7683: you cannot create a reference to 'void'
1>C:\develop\vc\test65\test65.cpp(73,1): message : see reference to class template instantiation 'std::list<R,std::allocator<R>>' being compiled
1> with
1> [
1> R=void
1> ]
1>C:\develop\vc\test65\test65.cpp(68,60): message : while compiling class template member function 'void SignalWithCombiner<OptionalLastValue<R>,R (void)>::operator ()(void)'
1> with
1> [
1> R=void
1> ]
1>C:\develop\vc\test65\test65.cpp(97,12): message : see the first reference to 'SignalWithCombiner<OptionalLastValue<R>,R (void)>::operator ()' in 'Destructible::~Destructible'
1> with
1> [
1> R=void
1> ]
1>C:\develop\vc\test65\test65.cpp(89,32): message : see reference to class template instantiation 'SignalWithCombiner<OptionalLastValue<R>,R (void)>' being compiled
1> with
1> [
1> R=void
1> ]
1>C:\develop\vc\test65\test65.cpp(100,17): message : see reference to class template instantiation 'Signal<void (void)>' being compiled
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(772): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(786,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(787,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(832,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(842,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(847,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(966,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(970,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(974,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1171,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1234,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1255,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1343,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1367,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1374,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1660,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(351,1): error C7683: you cannot create a reference to 'void'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xmemory(1485,1): message : see reference to class template instantiation 'std::_List_val<std::_List_simple_types<_Ty>>' being compiled
1> with
1> [
1> _Ty=void
1> ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(1852): message : see reference to class template instantiation 'std::_Compressed_pair<std::allocator<std::_List_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer>>,std::_List_val<std::_List_simple_types<_Ty>>,true>' being compiled
1> with
1> [
1> _Ty=void,
1> _Alloc=std::allocator<void>
1> ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\list(352,1): error C7683: you cannot create a reference to 'void'
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 26th, 2024, 07:42 AM
#8
Re: Should this be buildable with VC++17 ?
Thanks Juliadyer - if you get a chance, can you try building my code sample from post #6 and let us know what error(s) you see?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 30th, 2024, 03:42 AM
#9
Re: Should this be buildable with VC++17 ?
2kaud / JuliaDyer - I just got a reply from Microsoft to say that my code sample compiles correctly with VS2022 and /std:c++20. They apparently tried VS2022 versions 17.11.5 and 17.12P4.0. Are either of you able to try with any of those combinations? I'm using an earlier release here (VS2019) and only the free copy (I think it's called Community edition?) So I'm wondering if it's maybe only supported in the paid-for version
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 30th, 2024, 10:38 AM
#10
Re: Should this be buildable with VC++17 ?
Originally Posted by John E
2kaud / JuliaDyer - I just got a reply from Microsoft to say that my code sample compiles correctly with VS2022 and /std:c++20. They apparently tried VS2022 versions 17.11.5 and 17.12P4.0. Are either of you able to try with any of those combinations? I'm using an earlier release here (VS2019) and only the free copy (I think it's called Community edition?) So I'm wondering if it's maybe only supported in the paid-for version
Hi John,
but did you try to compile with /std:c++20?
Victor Nijegorodov
-
October 30th, 2024, 04:55 AM
#11
Re: Should this be buildable with VC++17 ?
Sorry, but I can't try a version higher than 17.6.5
So I'm wondering if it's maybe only supported in the paid-for version
No. There is no difference in the C++ language between the various VS2022/VS2017/VS2019 editions.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 31st, 2024, 02:58 AM
#12
Re: Should this be buildable with VC++17 ?
Originally Posted by 2kaud
Sorry, but I can't try a version higher than 17.6.5.
In case anybody else gets a chance, I've just had a reply back from Microsoft to say that 17.1 gives the errors I reported (C2182) and 17.2 gives the errors that 2kaud reported (C7683) but they're saying it's definitely been fixed since 17.11.3
Unfortunately (AFAIK) it isn't possible to install 17.11.3 using my current compiler, VS2019 - and I don't have enough disk space at the moment to install/upgrade to VS2022
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 30th, 2024, 11:02 AM
#13
Re: Should this be buildable with VC++17 ?
Hi Victor - yes I've tried /std:c++20 here but it made no difference. I've asked the Microsoft guy if he can let me have his .vcxproj file to experiment with. I'm hoping it might be some setting at his end that I've maybe de-selected here.
But I'm still concerned about the code for SgnalWithCombiner<Combiner, R(A...)>:perator() (A... a) and especially this line:-
Code:
typename std::conditional_t<std::is_void_v<R>, R, typename Combiner::result_type>
That definitely looks to me as if SgnalWithCombiner will be trying to return different types depending on whether R is deemed to be void or non-void
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 31st, 2024, 04:54 AM
#14
Re: Should this be buildable with VC++17 ?
I've now installed VS2022 onto a Windows 10 machine so that I can use the latest version (I normally use Windows 7 and 17.6.5 is the last version that will install with Windows 7).
I can confirm that the code compiles OK with 17.11.5.
I don't have enough disk space at the moment to install/upgrade to VS2022
If you're using Windows 10/11 then why not remove VS2019 and then install VS2022? VS2019 projects will convert to VS2022 OK. Also, if you're short of disk space have you removed any unwanted options from VS2019 using VS installer?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 31st, 2024, 06:49 AM
#15
Re: Should this be buildable with VC++17 ?
This might be my lucky day... I just did a disk cleanup and I'd nearly 12GB just in VS debugging reports! So after the cleanup I've now around 23GB of space remaining. If I get a chance later I might install VS2022 onto a memory stick (just to check how much space it'd take up)
One more thing 2kaud if you don't mind... if you've still got VS2022 installed on Win10, would you mind checking if my code will compile with C++17? The guy who wrote it seems to think it should - whereas the guy from Microsoft suggested it was C++20.
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|