Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 355052 - Wrong type deduced for `sizeof`
Summary: Wrong type deduced for `sizeof`
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 8.0.2   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-18 06:36 EDT by Tomasz Wesolowski CLA
Modified: 2011-09-19 08:23 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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