正如你在这里看到的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)