Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22237

A friend abbreviated template function - clang and gcc differ

$
0
0

The following code compiles with clang but not with gcc:

template<typename T>class number {    T num;public:    number(T num = 0): num(num) {}    friend auto add(auto a, auto b);};auto add(auto a, auto b) {    // the decltype(a) is needed to make clang happy    // see: https://stackoverflow.com/questions/62779242    return number<decltype(a)>{a}.num + number<decltype(b)>{b}.num;}int main() {    auto result = add(1.0, 2.0);}

Compilation error provided by gcc (version 10.1 with -std=c++20):

In instantiation of 'auto add(auto:13, auto:14) [with auto:13 = double; auto:14 = double]':error: 'double number<double>::num' is private within this context   return number<decltype(a)>{a}.num + number<decltype(b)>{b}.num;

Is it reasonable to assume this is a gcc bug?


Viewing all articles
Browse latest Browse all 22237

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>