* Recover the type of an `auto`-declared local from its initializer on the * declaration line — `auto x = Foo::instance();`, `auto w = make_unique ();`, * `auto p = new W();`, `auto w = Widget();` (#645).
( line: string, receiverName: string, ref: UnresolvedRef, context: ResolutionContext, depth: number, )
| 854 | * `auto p = new W();`, `auto w = Widget();` (#645). |
| 855 | */ |
| 856 | function inferCppAutoInitializerType( |
| 857 | line: string, |
| 858 | receiverName: string, |
| 859 | ref: UnresolvedRef, |
| 860 | context: ResolutionContext, |
| 861 | depth: number, |
| 862 | ): string | null { |
| 863 | const escaped = receiverName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 864 | const m = line.match(new RegExp(`\\b${escaped}\\b\\s*=\\s*([^;]+)`)); |
| 865 | if (!m || !m[1]) return null; |
| 866 | const init = m[1].trim(); |
| 867 | |
| 868 | const neu = init.match(/^new\s+([A-Za-z_][\w:]*)/); |
| 869 | if (neu && neu[1]) return cppLastSegment(neu[1]); |
| 870 | |
| 871 | // A call or construction: `Foo(...)`, `A::b(...)`, `make_unique<T>(...)`. |
| 872 | const call = init.match(/^([A-Za-z_][\w:]*(?:\s*<[^>;]*>)?)\s*\(/); |
| 873 | if (call && call[1]) return resolveCppCallResultType(call[1].replace(/\s+/g, ''), ref, context, depth + 1); |
| 874 | |
| 875 | return null; |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * Resolve a C++ chained call whose receiver is itself a call — encoded by the |
no test coverage detected