Can main () and its parameters have attributes?
In standard C ++, can a function main
and its parameters have attributes?
For example, is this the next legal one?
[[noreturn]] int main() { std::abort(); }
or something like
[[nodiscard, carries_dependency]]
int main(int argc [[maybe_unused]],
char * argv [[carries_dependency, maybe_unused]] [])
{ /* ... function body omitted ... */ }
+3
source to share
1 answer
Yes, it is legal. There is no C ++ standard (in [basic.start.main] , [dcl.attr], or elsewhere) to prevent this from happening . You can even mark it main()
as [[deprecated]]
if you like.
+4
source to share