Do I understand correctly about [basic.link] / 7 in the N4140?

VS2015 compiles and executes the following snippet without any problems. g ++ and clang do not bind code, and I think they are correct.

#include <iostream> namespace X { void p() { void q(); // This is a block scope declaration of the function q() with external // linkage (by ยง3.5/6), which then must be defined in namespace X, // according to ยง3.5/7, and not in the global namespace. q(); } } void q() { std::cout << "q()" << '\n'; } int main() { X::p(); } 
+5
source share
1 answer

Your example is almost identical to yours in [basic.link] / 7 - Yes, your interpretation is correct.
Using the undefined q function makes your program poorly formed NDR . Therefore, VC ++ is technically consistent. However, you definitely want to report it.

Note that VC ++ produces the same output ("q ()"), even if we add the internal definition of q :

 namespace X { void p() { void q(); q(); } void q() { std::cout << "This would be right"; } } void q() { std::cout << "q()" << '\n'; } 

... but has reasonable behavior when extern used .

+4
source

Source: https://habr.com/ru/post/1234716/


All Articles