我在运行ArchLinux的系统上使用clang
版本4.0.0,它总是运行良好,但最近我不能编译使用某些STL标头的程序了!
详细信息:
clang --version
的输出:
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
gcc --version
的输出:
gcc (GCC) 7.1.1 20170528
示例:
我尝试编译以下简单的程序:
#include <functional>
int main()
{
return 0;
}
我使用以下命令:
clang++ -std=c++1z test.cxx
结果是失败:
In file included from test.cxx:3:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/functional:60:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/unordered_map:47:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/bits/hashtable.h:37:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/bits/node_handle.h:39:
/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>;
^
3 errors generated.
这是STL中的错误还是我的设置搞砸了?
答案 0 :(得分:7)
您的设置搞砸了。有趣的是,我有完全相同的问题。
当你升级到gcc 7.1.1时,libstdc ++(它是gcc的标准库)与它一起更新,以提供C ++ 17的新功能。使用gcc,这是有效的,因为它几乎完全支持C ++ 17。
但是clang并没有。提示是<Window.Resources>
<Style TargetType="ListBox" x:Key="listBoxStyle">
<Setter Property="ItemsSource" Value="{Binding Source1}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Tag.IsChecked}" Value="True">
<Setter Property="ItemsSource" Value="{Binding Source2}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<CheckBox VerticalAlignment="Top" Name="checkBox"/>
<ListBox Margin="0,20,0,0" Tag="{Binding ElementName=checkBox}" Style="{StaticResource listBoxStyle}"/>
</Grid>
标志,而不是gcc&#39; -std=c++1z
标志。 Clang缺少deduction guides,当它在libstdc ++中遇到它们时,它不知道如何处理它们。
您可以从ALA安装旧的libstdc ++软件包,也可以下载/使用LLVM的标准库libc++,它自然只具有部分C ++ 17功能。