Another great piece by Eli on how Clang solves this problem and the nested functions inside C++ classes is
https://eli.thegreenplace.net/2012/07/05/how-clang-handles-t....
Clang basicaly moves the semantic processing to another pass, and tokenizes both types and variables as ‘identifiers’.
I’d agree that C/C++ have some sort context sensitivity. However I think this is not an ambiguity. You can deduce a single logical solution when you see T *x; . If the T in scope is a variable you do multiplication, if the T in scope is a type definition you make a variable declaration.
Real ambiguity happens when there are two logical solutions to the same statement and the language specification has to prefer one to remove ambiguity and undefined behaviour.
For example a C# code example from spec that is ambigious and therefore doesn’t compile:
“
static void F(bool a, bool b) {
Console.Writeline($”{a} and {b}”);
}
static void Main(string[] args) {
int G = 2;
int A = 1;
int B = 2;
F(True, False);
F(G<A, B>(7));
”
The compiler prefers to interpret the last line as a function call with one argument, which is a call to a generic method G (that doesn’t exist in the code above) with two type arguments a one regular argument. Instead of one function call with two boolean arguments.