小编New*_*fer的帖子

为什么这个模板constexpr函数不能在gcc上编译但在clang上运行良好?

正如你在这里看到的http://melpon.org/wandbox/permlink/vJSyO14mkbH0MQRq这个不能在gcc上编译时出错:

prog.cc: In instantiation of 'constexpr B convert(A) [with A = unsigned char; B = short unsigned int]':
prog.cc:16:52:   required from here
prog.cc:12:1: error: body of constexpr function 'constexpr B convert(A) [with A = unsigned char; B = short unsigned int]' not a return-statement
Run Code Online (Sandbox Code Playgroud)

代码:

#include <stdint.h>
#include <limits>
#include <iostream>

template< typename A, typename B >
constexpr B convert( A a )
{
    auto aMax = std::numeric_limits< A >::max();
    auto bMax = std::numeric_limits< B >::max();

    return a …
Run Code Online (Sandbox Code Playgroud)

c++ gcc clang c++14

0
推荐指数
1
解决办法
300
查看次数

标签 统计

c++ ×1

c++14 ×1

clang ×1

gcc ×1