Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #86796
| From | Manfred <noname@add.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Is this valid C++ code? |
| Date | 2022-10-05 02:54 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <thikk1$4vd$1@gioia.aioe.org> (permalink) |
| References | <bc46c146-abb5-4b16-b62d-324e049c7083n@googlegroups.com> <jq2kr7Ft790U1@mid.individual.net> |
On 10/4/2022 1:47 PM, Bo Persson wrote:
> On 2022-10-03 at 23:09, daniel...@gmail.com wrote:
>> Hello everyone,
>>
>> Is the C++ code below valid?
>>
>> #include <iostream>
>> #include <string_view>
>> #include <string>
>>
>> template <class T, class Enable = void>
>> class Foo
>> {};
>>
>> template <class T>
>> class Foo<T,typename
>> std::enable_if<std::is_same<T,std::string>::value>::type>
>> {
>> public:
>> void f(std::string s)
>> {
>> Foo<std::string_view> foo; // (*)
>> foo.f(s);
>> }
>> };
>>
>> template <class T>
>> class Foo<T, typename std::enable_if<std::is_same<T,
>> std::string_view>::value>::type>
>> {
>> public:
>> void f(std::string_view s)
>> {
>> std::cout << s << "\n";
>> }
>> };
>>
>> int main()
>> {
>> Foo<std::string> foo;
>> foo.f("Hello World");
>> }
>>
>> LLVM (clang-cl) says "yes", and outputs "Hello World".
>>
>> Visual Studio 2022 (v143) says "no", "'f': is not a member of
>> 'Foo<std::basic_string_view<char,std::char_traits<char>>,void>", 17
>> at line (*)
>>
>> Both compiled with C++17.
>>
>
> Seems like g++ (v12.2) agrees with VC++, and also points out the problem
> that the specialization is defined after its first use.
>
> My (non-language-lawyer) interpretation is that since f and its local
> foo don't depend on the template parameter T, they should be looked up
> immediately, and not at the point of instantiation.
>
>
A good example of when someone's question, and its answer, are useful
for someone else too.
Thanks.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is this valid C++ code? "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-10-03 14:09 -0700
Re: Is this valid C++ code? David LaRue <huey.dll@tampabay.rr.com> - 2022-10-03 23:52 +0000
Re: Is this valid C++ code? "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-10-03 18:07 -0700
Re: Is this valid C++ code? "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-10-03 18:42 -0700
Re: Is this valid C++ code? Juha Nieminen <nospam@thanks.invalid> - 2022-10-04 06:05 +0000
Re: Is this valid C++ code? Bo Persson <bo@bo-persson.se> - 2022-10-04 13:47 +0200
Re: Is this valid C++ code? "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-10-04 05:22 -0700
Re: Is this valid C++ code? Manfred <noname@add.invalid> - 2022-10-05 02:54 +0200
Re: Is this valid C++ code? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-07 12:41 -0700
Re: Is this valid C++ code? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-08 11:18 -0700
csiph-web