Program with std::variant works in msvc but not in gcc

I wrote the following program that works with msvc c++17 but rejected by gcc and clang. I want to know which compiler is right here. Demo #include <variant> struct C { std::variant<bool> mem; C(std::variant<bool> p): mem(p) { } }; int main() { C c(1); //works with msvc but not with gcc and clang } GCC… Read More Program with std::variant works in msvc but not in gcc

Passing unique pointer to function in a lambda capture for parallel execution

This question is a follow-up to this one. Of note, by removing the <execution> header and using the std::for_each() overload with no execution strategy, it works well. I have a setup with a minimal reproducing example shown below. Base class A is pure virtual and the two derived classes have different versions of a function… Read More Passing unique pointer to function in a lambda capture for parallel execution

Forward declaration not working when using as argument in a member function

My forward declaration for class B; before class A doesn’t work in the below code, even when this answer mentions that a forward declaration of an incomplete type should work when used in arguments of a function. It throws an error in A::func() saying "undefined type B". What should be the fix for this, and… Read More Forward declaration not working when using as argument in a member function

MSVC fails to specialize template with `std::enable_if` and a non-type argument

This is a follow-up question to MSVC fails to deduce template argument I am unable to find any combination that works on Visual Studio Enterprise 2019 (VS 16.11, MSVC 19.29). clang, g++ and MSVC 19.33 and later (without /permissive-) compile this code. MSVC 19.29 does not even if using /permissive-. It looks a lot like… Read More MSVC fails to specialize template with `std::enable_if` and a non-type argument

Constructor inheritance in C++. Derived class's default constructor is not being called

I have this sample code: #include <iostream> class A { public: A() { std::cout << "Default constructor of A" << ‘\n’; } A(int i) { std::cout << "Inside the constructor of A with one int argument" << ‘\n’; } }; class B : A { using A::A; public: B() { std::cout << "Default constructor of… Read More Constructor inheritance in C++. Derived class's default constructor is not being called

MSVC fails to deduce template argument

This C++17 code compiles with clang and g++ but MSVC fails to deduce the template argument: #include <type_traits> struct Prop { constexpr Prop() {}; }; constexpr const Prop i; struct Klass { template <auto Klass::*MEMBER, const Prop &P, std::enable_if_t<std::is_member_pointer_v<decltype(MEMBER)>, bool> = true> void def() {} void fn(); int var; }; void Klass::fn() {} int main()… Read More MSVC fails to deduce template argument

C++ Q: Illegal member initialization trying to set base class member in derived

EDITED: Removed the Base class being a template class, as this has no bearing on the issue as others have pointed out to me. It has been a while since working with basic C++ concepts, and specifically the nuances of member initialization lists. https://en.cppreference.com/w/cpp/language/constructor class Base { public: Base() {} protected: int m_Value; }; class… Read More C++ Q: Illegal member initialization trying to set base class member in derived

Why doesn't std::is_invocable_r_v<void, TFun> return false if the function does not return void

See the test case #include <iostream> #include <type_traits> int main(){ const char* hw = "hello world"; auto task = [hw] ()->const char * { return hw ; }; std::cout << std::is_invocable_r_v<const char *, decltype(task)> << std::endl; std::cout << std::is_invocable_r_v<void, decltype(task)> << std::endl; std::cout << std::is_invocable_r_v<const char, decltype(task)> << std::endl; } Result is 1 1 0… Read More Why doesn't std::is_invocable_r_v<void, TFun> return false if the function does not return void