You are not logged in.
Hello all,
first time posting here. Hope it's the right place.
I have a few projects where I use std::unordered_map provided by gcc-libs aka libstdc++. Since upgrading gcc-libs from previously 6.3.1-2 to 7.1.1-2 I get the following error message when compiling translation units using std::unordered_map.
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:27: error: use of class template 'optional' requires template arguments
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:451:11: note: template is declared here
class optional
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:40: error: expected ';' at end of declaration
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:41: error: cannot use arrow operator on a type
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
The compile flags are
-std=c++1z -W -Wall -pedantic
I am looking forward to your help.
Regards,
Immanuel
Last edited by immanuel (2017-05-31 14:28:31)
Offline
Can you supply a minimal example?
Offline
Compile this code
/*-- demo.cpp --*/
#include <unordered_map>
int main()
{
return 0;
}
with
clang++ -std=c++1z -W -Wall -pedantic demo.cpp
I forgot to mention i use clang. It does compile properly with gcc, though.
Offline
Aha, it seems this is due to differences in clang and gcc. Please inspect the following code snippet:
template<typename T>
struct optional { };
template<typename T> optional(T) -> optional<T>;
int main()
{
return 0;
}
This compiles with g++ but not with clang++ (yielding the same error message(s)). I again use the compile flags
-std=c++1z -W -Wall -pedantic
Now what is the meaning of the 4th line?
template<typename T> optional(T) -> optional<T>;
AFAIK C++11 introduced an alternate function syntax with a "trailing-return-type". But then the keyword "auto" is required before the function name. So i guess it is a class template deduction guide [1], introuced in C++17 and which i was not aware of until now. I suppose clang 4.0.0 does not support this language feature yet
Offline
I suppose clang 4.0.0 does not support this language feature yet
You should be able to post this upstream as a feature request, if you so desire. I'ver never used clang (haven't needed to) so I don't know for certain. But it couldn't hurt to ask the clang devs.
I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.
Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...
Offline
@JohnBobSmith it seems this is the way to go.
Anyways, everyone who uses clang together with libstdc++ and tries to compile a TU including <optional> will run into this issue. So clang will have to support this or break compatibility.
For now, i just commented that particular line
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
in include/c++/7.1.1/optional:1032:27.
Thanks for the help, guys.
Best,
Immanuel
Last edited by immanuel (2017-05-31 14:30:13)
Offline
Why is this marked as solved ?
An archlinux bug report should be opened and our clang 4.0 patched.
Offline
I've opened https://bugs.archlinux.org/task/54276
Offline