Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp =================================================================== --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3639,6 +3639,16 @@ clang::QualType qual_type(GetQualType(type)); + // Remove certain type sugar from the name. Sugar such as elaborated types + // or template types which only serve to improve diagnostics shouldn't + // act as their own types from the user's perspective (e.g., formatter + // shouldn't format a variable differently depending on how the ser has + // specified the type. '::Type' and 'Type' should behave the same). + // Typedefs and atomic derived types are not removed as they are actually + // useful for identifiying specific types. + qual_type = RemoveWrappingTypes(qual_type, + {clang::Type::Typedef, clang::Type::Atomic}); + // For a typedef just return the qualified name. if (const auto *typedef_type = qual_type->getAs()) { const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); Index: lldb/test/API/lang/cpp/elaborated-types/Makefile =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/elaborated-types/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules Index: lldb/test/API/lang/cpp/elaborated-types/TestElaboratedTypes.py =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/elaborated-types/TestElaboratedTypes.py @@ -0,0 +1,40 @@ +""" +Test elaborated types (e.g. Clang's ElaboratedType or TemplateType sugar). +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.build() + self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + + # Test that a plain elaborated type is only in the display type name but + # not in the full type name (which is what the formatters use). + result = self.expect_expr("::Struct s; s", result_type="::Struct") + self.assertEqual(result.GetTypeName(), "Struct") + + # Test the same for template types (that only act as sugar to better + # show how the template was specified by the user). + + # Declare a template that can actually be instantiated. + # FIXME: The error message here is incorrect. + self.expect("expr --top-level -- template struct $V {};", + error=True, substrs=["Couldn't find $__lldb_expr() in the module"]) + result = self.expect_expr("$V<::Struct> s; s", + result_type="$V< ::Struct>") + self.assertEqual(result.GetTypeName(), "$V") + + # Add a hex formatter for a typedef of int. + self.expect("type format add 'Typedef' -f x") + # Make sure a variable where only the actual type name but not the + # elaborated name ("::Typedef") match our formatters is still correctly + # formatted. + self.expect_expr("::Typedef value = 3; value", result_value="0x00000003") Index: lldb/test/API/lang/cpp/elaborated-types/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/elaborated-types/main.cpp @@ -0,0 +1,10 @@ +typedef int Typedef; +struct Struct { + Typedef x; +}; + +int main() { + Struct use; + use.x = 3; + return use.x; // break here +}