Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using [[deprecated]] the warning is given 3 times

Tags:

c++

c++14

I found this question/answer which describes the use of [[deprecated]] as a C++14 feature to instruct the compiler to warn about the use of deprecated functions.

I tried using this in a simple function within a project - the warning was issued 3 times. I initially thought this might be multiple template instantiations, so I tested a simple program.

[[deprecated]] void doNothing() {}

int main(){
    doNothing();
}

g++ -std=c++14 deprecatedTest.cpp outputs

deprecatedTest.cpp: In function 'int main()':
deprecatedTest.cpp:4:5: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]
     doNothing();
     ^
deprecatedTest.cpp:1:21: note: declared here
 [[deprecated]] void doNothing() {}
                     ^
deprecatedTest.cpp:4:5: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]
     doNothing();
     ^
deprecatedTest.cpp:1:21: note: declared here
 [[deprecated]] void doNothing() {}
                     ^
deprecatedTest.cpp:4:15: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]
     doNothing();
               ^
deprecatedTest.cpp:1:21: note: declared here
 [[deprecated]] void doNothing() {}

Is the warning supposed to be printed 3 times? (To get more attention?)

This seems a strange behaviour, but I can't imagine a simpler test.

like image 807
chrisb2244 Avatar asked Dec 20 '25 21:12

chrisb2244


1 Answers

This is an obvious Quality of Implementation issue, and not likely to be intentional.

Just raise it on GCC Bugzilla if it's not already there.

OP has raised this on Bugzilla, as suggested. ☺

like image 51
Lightness Races in Orbit Avatar answered Dec 23 '25 12:12

Lightness Races in Orbit