-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
01函数模板中的代码,gcc13.2 及以前的编译器运行存在 bug,已在 gcc14.1 被修复 #25
Comments
我完全清楚的知道这个问题,这是我故意为之,我并不想在此时就开始教学 std::declval,过于抽象,前期视频使用简单的 你可以关注到教案的后续内容,在 SFINAE 中单独拿出一节来讲这个问题:
|
GCC 的报错是:
先留着吧,把函数调用那里换成 我感觉这是 GCC 的 bug,至少数组和 std::string 完全可以直接( |
#include <iostream>
#include <type_traits>
using namespace std::string_literals;
template<typename T1, typename T2,
typename RT = decltype(true ? T1{} : T2{})>
RT max (T1 a, T2 b) {
return b < a ? a : b;
}
int main(){
auto ret = ::max("1", "2"s);
std::cout << ret << '\n';
} gcc 可以通过编译,我只是去除了 CVR,我感觉没有道理:https://godbolt.org/z/sWWePaf99 |
这个 labels 怎么乱七八糟的。 |
是 gcc 的 bug ,已经修复了。 参考:
看起来大家都没有习惯检查 trunk 的表现…… |
合理,和我猜想一样。 的确没有检查 trunk 的习惯。 |
已发布 gcc14,解决了 gcc13.2 及以前的这块 bug,再次强调一下。 |
https://github.com/Mq-b/Modern-Cpp-templates-tutorial/blob/main/md/%E7%AC%AC%E4%B8%80%E9%83%A8%E5%88%86-%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/01%E5%87%BD%E6%95%B0%E6%A8%A1%E6%9D%BF.md
在gcc不能运行
https://godbolt.org/z/685Y95vKW
T1,T2不一定是可{}构造的,应用declval,且去除引用返回
需改成如下
https://godbolt.org/z/xd14YaPx6
The text was updated successfully, but these errors were encountered: