In C++ it is possible to use the static
keyword within a translation unit to affect the visibility of a symbol (either variable or function declaration).
In n3092, this was deprecated:
Annex D.2 [depr.static]
The use of the static keyword is deprecated when declaring objects in namespace scope (see 3.3.6).
In n3225, this has been removed.
The only article I could find is somewhat informal.
It does underline though, that for compatibility with C (and the ability to compile C-programs as C++) the deprecation is annoying. However, compiling a C program directly as C++ can be a frustrating experience already, so I am unsure if it warrants consideration.
Does anyone know why it was changed ?
In C++ Standard Core Language Defect Reports and Accepted Issues, Revision 94 under 1012. Undeprecating static` they note:
Basically saying that the deprecation of
static
doesn't really make sense. It won't ever be removed from C++, and it's still useful because you don't need the boilerplate code you need with unnamed namespaces, if you just want to declare a function or object with internal linkage.Deprecated or not, removing this language feature would break existing codes and annoy people.
The whole static deprecation thing was just wishful thinking along the lines of "anonymous namespaces are better than static" and "references are better pointers". Lol.
I will try to answer your question, although it is an old question, and it does not look very important (it really is not very important in itself), and it has received quite good answers already. The reason I want to answer it is that it relates to fundamental issues of standard evolution and language design when the language is based on an existing language: when should language features be deprecated, removed, or changed in incompatible ways?
The linkage actually.
Deprecation indicates:
The latter point is important. Although there is never a formal promise that your program won't be broken, sometimes silently, by the next standard, the committee should try to avoid breaking "reasonable" code. Deprecation should tell programmers that it is unreasonable to depend on some feature.
It is very important to preserve a C/C++ common subset, especially for header files. Of course,
static
global declarations are declarations of symbol with internal linkage and this not very useful in a header file.But the issue is never just compatibility with C, it's compatibility with existing C++: there are tons of existing valid C++ programs that use
static
global declarations. This code is not just formally legal, it is sound, as it uses a well-defined language feature the way it is intended to be used.Just because there is now a "better way" (according to some) to do something does not make the programs written the old way "bad" or "unreasonable". The ability of using the
static
keyword on declarations of objects and functions at global scope is well understood in both C and C++ communities, and most often used correctly.In a similar vein, I am not going to change C-style casts to
double
tostatic_cast<double>
just because "C-style casts are bad", asstatic_cast<double>
adds zero information and zero safety.The idea that whenever a new way to do something is invented, all programmers would rush to rewrite their existing well-defined working code is just crazy. If you want to remove all the inherited C ugliness and problems, you don't change C++, you invent a new programming language. Half-removing one use of
static
hardly makes C++ less C-ugly.Code changes need a justification, and "old is bad" is never a justification for code changes.
Breaking language changes need a very strong justification. Making the language very slightly simpler is never a justification for a breaking change.
The reasons given why
static
is bad are just remarkably weak, and it isn't even clear why not both objects and function declarations are deprecated together - giving them different treatment hardly makes C++ simpler or more orthogonal.So, really, it is a sad story. Not because of the practical consequences it had: it had exactly zero practical consequences. But because it shows a clear lack of common sense from the ISO committee.