Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355052

Summary: Wrong type deduced for `sizeof`
Product: [Tools] CDT Reporter: Tomasz Wesolowski <kosashi>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 8.0   
Target Milestone: 8.0.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Tomasz Wesolowski CLA 2011-08-18 06:36:25 EDT
Case 1 (C++):
#include <cstddef>
void a() {
	typedef float size_t;
	sizeof(10); // wrong - getExpressionType returns float
	sizeof(int); // wrong - getExpressionType returns float
}

Case 2(C):
#include <stddef.h>
void foo() {
	sizeof(float); // correct
	sizeof(1.0); // wrong - getExpressionType returns double
}

For case 1, see:
org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.get_SIZE_T(IASTNode)
(should only check global scope, I think?)

For case 2, see:
org.eclipse.cdt.internal.core.dom.parser.c.CASTUnaryExpression.getExpressionType()
(doesn't handle some operators like sizeof)
Comment 1 Markus Schorn CLA 2011-09-06 09:55:46 EDT
Added testcase and fix.
Comment 2 CDT Genie CLA 2011-09-06 10:23:02 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 355052: Type of sizeof expression.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=0e70cab1786e1e7902164e6f25e3735a3109b092
Comment 3 CDT Genie CLA 2011-09-19 08:23:15 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 355052: Type of sizeof expression.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=a0b81bac32fec837d38ec3122c42c21086fa8097