Internal compiler error MSVC

Creating a new thread since the previous one is solved:
https://cplusplus.com/forum/general/285225/

There is a different issue right now, and I would like to ask you if you can reproduce the Internal compiler error with the following code which fails with MSVC:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <string>
#include <cuchar>
#include <iostream>
#include <type_traits>

template<typename StringType, typename... Args>
using Function = std::size_t(*)(Args...);

template<typename StringType>
	requires std::is_same_v<typename StringType::value_type, char16_t> ||
std::is_same_v<typename StringType::value_type, char32_t>
void SomeFunction(const StringType & param)
{
	Function func = nullptr;
	std::mbstate_t state{};
	char char_buff[MB_LEN_MAX]{};

	if constexpr (std::is_same_v<typename StringType::value_type, char16_t>)
		func = std::c16rtomb;
	else if constexpr (std::is_same_v<typename StringType::value_type, char32_t>)
		func = std::c32rtomb;

	static_assert(func != nullptr);

	const typename StringType::value_type char_type = param.at(0);
	const std::size_t result = func(char_buff, char_type, &state);
	std::cout << result << std::endl;
}

int main()
{
	std::u32string str = U"test";
	SomeFunction(str);
        return 0
}


Is that indeed compiler issue or did I do something wrong?

from what I see by running it on cpp.sh with g++ it's unable to include cuchar header so the issue is not same, but cuchar header is there since C++ 11
Last edited on
Problem fixed, issue was invalid function pointer declaration.

This works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
template<typename StringType, typename... Args>
	requires std::is_same_v<typename StringType::value_type, char16_t> ||
std::is_same_v<typename StringType::value_type, char32_t>
void SomeFunction(const StringType & param)
{
	Function<StringType, char*, typename StringType::value_type, mbstate_t*> func = nullptr;
	std::mbstate_t state{};
	char char_buff[MB_LEN_MAX]{};

	if constexpr (std::is_same_v<typename StringType::value_type, char16_t>)
		func = std::c16rtomb;
	else if constexpr (std::is_same_v<typename StringType::value_type, char32_t>)
		func = std::c32rtomb;

	const typename StringType::value_type char_type = param.at(0);
	const std::size_t result = func(char_buff, char_type, &state);
	std::cout << result << std::endl;
}

int main()
{
	std::u32string str = U"test";
	SomeFunction(str);
}


MSVC could be a bit more user friendly with diagnostics but it isn't...
Last edited on
if its the latest version, I would report it.
It's the latest compiler version and I was compiling with std:c++20

Good suggestion, I'll report it to MS dev community.
Registered users can post here. Sign in or register to post.