From 969c689d893a248eca4f049f5b89f747e66e4bff Mon Sep 17 00:00:00 2001
From: Douglas Gregor
If the user was somehow confused about how the system "pid_t" typedef is defined, Clang helpfully displays it with "aka".
+In C++, type preservation includes retaining any qualification written into type names. For example, if we take a small snippet of code such as: + +
++ ++namespace services { + struct WebService { }; +} +namespace myapp { + namespace servers { + struct Server { }; + } +} + +using namespace myapp; +void addHTTPService(servers::Server const &server, ::services::WebService const *http) { + server += http; +} ++
and then compile it, we see that Clang is both providing more accurate information and is retaining the types as written by the user (e.g., "servers::Server", "::services::WebService"): + +
+ $ g++-4.2 -fsyntax-only t.cpp + t.cpp:9: error: no match for 'operator+=' in 'server += http' + $ clang -fsyntax-only t.cpp + t.cpp:9:10: error: invalid operands to binary expression ('servers::Server const' and '::services::WebService const *') + server += http; + ~~~~~~ ^ ~~~~ ++ +
Naturally, type preservation extends to uses of templates, and Clang retains information about how a particular template specialization (like std::vector<Real>
) was spelled within the source code. For example:
+ $ g++-4.2 -fsyntax-only t.cpp + t.cpp:12: error: no match for 'operator=' in 'str = vec' + $ clang -fsyntax-only t.cpp + t.cpp:12:7: error: incompatible type assigning 'vector<Real>', expected 'std::string' (aka 'class std::basic_string<char>') + str = vec; + ^ ~~~ ++
simple example + template<> example
@@ -203,11 +245,6 @@ implements the "wwopen" class of APIs):In practice, we've found that this is actually more useful in multiply nested macros that in simple ones.
-...
- -