Based on discussions about the use of specific supplier attributes in another question, I asked myself: "what rules should we specify for people to use attributes that are not specified in the standard ?"
Two attributes that are defined: [[ noreturn ]] and [[ carries_dependencies ]] . The standard leaves open how compilers should respond to unknown attributes - thus, by the standard, they can stop with an error message. This is not what, for example, GCC does, it issues a warning and continues. This is probably the behavior expected from most common compilers. For this reason, I would like to read "should" in the standard, but we do not have it.
Document N2553 displays flexible attributes. It lists additional attributes used by GCC ( unused , weak ) and MSVC ( dllimport ). for OpenMP, a widely supported parallelizing structure, cloud attributes are offered, for example. omp::for(clause, clause) , omp::parallel(clause,clause) . Thus, it is very likely that we will use some specific attributes for providers very soon after they generally support the syntax.
Therefore, when we now “go out into the world” and tell people about C ++ 11, what should be advice on the use of attributes?
- Use only
noreturn and carries_dependencies - Use the old compiler syntax instead.
__attribute__((noreturn)) and define a macro when transferring code (current situation) - Use the attributes that your favorite compiler freely supports, knowing that this code cannot be portable to another standard compiler, because if the standard allows the compiler to stop with an error, you should think that this will happen. It sounds a bit like propaganda for writing non-portable code.
- Or, I suppose, we expect the most used compilers to warn about unknown attributes, so you can use vendor-specific attributes, bearing in mind that in rare cases you may have problems.
Note the slight difference in the last two markers. Although both say that “use the attributes you need,” the item3 message “does not care about other compilers”, while item4 implicitly rephrases the standard texts “implementation-defined behavior”, “the compiler should issue a diagnostic message”.
What could be the suggestion for the upcoming best practice here?
source share