namespace M
{
int h;
}
inline namespace M
{
int j = 6;
}
This will cause the error 'non-inline namespace cannot be opened as an inline namespace
You have to use:
inline namespace M
{
int h;
}
inline namespace M
{
int j = 6;
}
The other way around, you should just get a warning that you are reopening an inline namespace as a non-inline namespace
inline namespace M
{
int h;
}
namespace M
{
int j = 6;
}
But it doesn't change anything at all from what I can tell so I don't know why the warning exists, but the fact it exists and ::inline
suggests otherwise.
namespace M
{
inline namespace F {
int h;
}
}
namespace M::F {
int k;
}
gives the same warning, which is suppressed when using:
namespace M::inline F {
int k;
}
Interestingly, this is illegal:
inline namespace M
{
inline namespace F {
int h;
}
}
inline namespace M::inline F {
int k;
}
You can either use namespace M::inline F
or namespace M::F
but you will get a warning in both cases that you are opening inline namespace M as a non-inline namespace.
It may just be that ::inline
only exists to suppress that warning and to make the programmer aware from the extension namespace that it is an inline namespace that can be accessed without a scope resolution operator without them having to check the main namespace definition, which makes the code and intention clear, and because most inline namespaces are used for versioning where they are always nested inside a non-inline namespace at global namespace scope, the syntax inline namespace M::inline F
wasn't needed to be allowed. Previously namespace M {inline F {int k;}}
had to be used instead of namespace M::F
to make that intention clear on the extension namespace block.