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

Why [[likely]] attribute in C++20 raises a warning here?

$
0
0
#include <iostream>int foo(int a, int b){    if(a < b) [[likely]] {        return a;    }    return b;}int main(){    std::cout << foo(3,1) << std::endl;}

Demo

According to the reference, it seems like this is how we're supposed to decorate if clauses with [[likely]] or [[unlikely]] attributes. It's also supported in C++20 (see here).

However, I'm running into a warning:

main.cpp: In function 'int foo(int, int)':main.cpp:5:15: warning: attributes at the beginning of statement are ignored [-Wattributes]    5 |     if(a < b) [[likely]] {      |               ^~~~~~~~~~

The codebase is strict about warnings, and this will cause builds to fail. So, am I doing something wrong, or is this a bug?

g++ version on my macbook:

g++-9 (Homebrew GCC 9.3.0_1) 9.3.0Copyright (C) 2019 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Viewing all articles
Browse latest Browse all 22016

Trending Articles



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