https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94764

            Bug ID: 94764
           Summary: block extern incorrectly resolved to external linkage
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tabloid.adroit at gmail dot com
  Target Milestone: ---

Related to DR426

source: 
https://stackoverflow.com/questions/61276220/why-same-named-extern-local-variables-in-different-blocks-get-different-linkages


// foo.cpp
int var = 10;                // external linkage

// main.cpp
#include <iostream>

static int var = 100;        // internal linkage

int main() {
    extern int var;          // internal linkage
    std::cout << var << std::endl;
    {
        extern int var;      // g++: external linkage , clang++: internal
linkage
        std::cout << var << std::endl;
        {
            extern int var;  // g++: external linkage , clang++: internal
linkage
            std::cout << var << std::endl;
        }
    }
}    

g++ : "100 10 10"
clang++ : "100 100 100" (msvc++)

[basic.link] #6 is pretty clear about this. I'm not sure it is a UB.

Reply via email to