-
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 19th, 2024, 07:41 AM
#2
Re: Should this be buildable with VC++17 ?
Yes, this should be buildable with VC++17, but the issue arises because MSVC handles PBD::Signal<void()> differently, specifically regarding the use of void() as a function signature. To resolve this, you can try modifying the PBD::Signal<void()> to PBD::Signal<void> (i.e., without parentheses) in the code.
Replace:
PBD::Signal<void()> Destroyed;
With:
PBD::Signal<void> Destroyed;
This should resolve the "illegal use of type void" error in MSVC.
Days calculator
Last edited by Juliadyer; October 20th, 2024 at 10:47 PM.
-
October 19th, 2024, 08:11 AM
#3
Re: Should this be buildable with VC++17 ?
Originally Posted by Juliadyer
PBD::Signal<void> Destroyed;
This should resolve the "illegal use of type void" error in MSVC.
Thanks @JuliaDyer and strangely enough, that's what it looked like in the first place. It recenty got changed by one of the other devs (who I can't get hold of at the moment). I tinkered around with some of the other simple data types - e.g. Signal<int()> Destroyed; and Signal<char()> Destroyed; and they both compile fine with MSVC - but it won't accept Signal<void()> Destroyed;
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 20th, 2024, 03:52 AM
#4
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
#5
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
#6
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
#7
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
#8
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
#9
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, 06:58 AM
#10
Re: Should this be buildable with VC++17 ?
Yes, this code should be buildable with VC++17, but the error you?re encountering with MSVC ("illegal use of type void") suggests that PBD::Signal<void()> may have issues with how MSVC handles void types in template arguments. MSVC can be more restrictive with void return types in certain contexts. sub des tages sonntag, To address this, you can try:
1- Wrapping PBD::Signal<void()> with a std::function<void()> to ensure it aligns with MSVC?s expectations.
2- Verifying whether the latest MSVC updates or modifications to PBD::Signal improve cross-compiler compatibility.
3- If feasible, contact the maintainers of PBD::Signal to confirm it fully supports MSVC?s C++17 handling of void.
These steps can help identify whether it?s a limitation in MSVC or in the library's implementation.
Last edited by Juliadyer; November 20th, 2024 at 06:44 AM.
-
October 26th, 2024, 07:42 AM
#11
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
#12
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, 04:55 AM
#13
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 30th, 2024, 10:38 AM
#14
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, 11:02 AM
#15
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
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
|