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

Bug 362464

Summary: [C] Sizeof calculation for plain C throws an IllegalArgumentException
Product: [Tools] CDT Reporter: Markus Schorn <mschorn.eclipse>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: angvoz.dev, cdtdoug, malaperle
Version: 8.0.2   
Target Milestone: 8.0.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Markus Schorn CLA 2011-10-31 06:37:47 EDT
* The exception is thrown, because the CPPVisitor is used for plain C nodes.
* I noticed that SizeofCalculator uses ICPPBasicType instead of IBasicType.

Sample code:
   typedef int T[sizeof(int)];

Exception:
java.lang.IllegalArgumentException
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createType(CPPVisitor.java:1841)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createType(CPPVisitor.java:1717)
	at org.eclipse.cdt.internal.core.dom.parser.Value.evaluate(Value.java:475)
	at org.eclipse.cdt.internal.core.dom.parser.Value.create(Value.java:363)
	at org.eclipse.cdt.internal.core.dom.parser.c.CArrayType.getSize(CArrayType.java:132)
...
Comment 1 Markus Schorn CLA 2011-11-02 04:25:04 EDT
*** Bug 362574 has been marked as a duplicate of this bug. ***
Comment 2 Markus Schorn CLA 2011-11-03 09:10:58 EDT
Added testcase and fix.
Comment 3 CDT Genie CLA 2011-11-03 09:23:07 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 362464: Sizeof computation for plain C.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=5a62f3280d7b55fef0ac4a0cf9f5d451de1f98a8
Comment 4 Marc-André Laperle CLA 2011-11-04 00:59:55 EDT
Hi Markus, I also get this exception on the latest build of 8.0.2 (8.0.0.201111030706). Would it be possible to port the fix to 8.0.2?
Comment 5 Markus Schorn CLA 2011-11-04 02:56:24 EDT
(In reply to comment #4)
> Hi Markus, I also get this exception on the latest build of 8.0.2
> (8.0.0.201111030706). Would it be possible to port the fix to 8.0.2?

Thanks, it slipped my attention that the fix for bug 361604 also went into 8_0.
Comment 6 CDT Genie CLA 2011-11-04 03:23:02 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 362464: Sizeof computation for plain C.

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