https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83342
Bug ID: 83342
Summary: extern marked variable template with later definition
emits error
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dacamara.cameron at gmail dot com
Target Milestone: ---
consider the scenario:
t.h:
#pragma once
template <typename T>
extern const int N;
t.cpp:
#include "t.h"
template <typename T>
const int N = sizeof(T);
template const int N<int>;
main.cpp:
#include <cassert>
int main() {
assert(N<int> == sizeof(int));
}
when gcc goes to compile t.cpp we get an error:
t.cpp: In instantiation of ‘const int N<int>’:
t.cpp:7:11: required from here
t.cpp:7:11: error: explicit instantiation of ‘N<int>’ but no definition
available [-fpermissive]
const int N<int>;
clang/msvc allow this. Clang links properly, msvc (currently) does not.