During some investigation related to "Variable template" I found out some strange code behaviour for me. Does standard say anything about this behaviour?
//Header.h
#pragma once
template<typename T>
auto myvar = []() -> T&{
static T v;
return v;
};
//Source.cpp
#include <iostream>
#include "Header.h"
void testFunction()
{
std::cout << myvar<int>() << '\n';
}
//main.cpp
#include <iostream>
#include "Header.h"
void testFunction();
int main(int argc, char **argv)
{
myvar<int>() = 10;
testFunction();
std::cout << myvar<int>() << '\n';
}
Output:
0
10
I expect:
10
10