mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 15:05:36 +02:00
Bug 457770 - Size of empty structure
Change-Id: Id6f02228968986090867b2053c7815e594a404c1 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
8a896c57ed
commit
327709c58e
2 changed files with 13 additions and 2 deletions
|
@ -21,6 +21,7 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
|
|||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.XVALUE;
|
||||
import static org.eclipse.cdt.core.parser.ParserLanguage.CPP;
|
||||
import static org.eclipse.cdt.core.parser.tests.VisibilityAsserts.assertVisibility;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -9079,6 +9080,15 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size;
|
||||
assertEquals(pointerSize, BSize);
|
||||
}
|
||||
|
||||
// struct waldo {};
|
||||
public void testSizeofEmptyStruct_457770() throws Exception {
|
||||
BindingAssertionHelper bh = getAssertionHelper();
|
||||
IASTName nameWaldo = bh.findName("waldo");
|
||||
ICPPClassType waldo = (ICPPClassType) nameWaldo.resolveBinding();
|
||||
long waldoSize = SizeofCalculator.getSizeAndAlignment(waldo, nameWaldo).size;
|
||||
assertNotEquals(0, waldoSize);
|
||||
}
|
||||
|
||||
// template <bool> struct B {};
|
||||
// template <>
|
||||
|
|
|
@ -329,8 +329,9 @@ public class SizeofCalculator {
|
|||
if (maxAlignment < info.alignment)
|
||||
maxAlignment = info.alignment;
|
||||
}
|
||||
if (size > 0)
|
||||
size += maxAlignment - (size - 1) % maxAlignment - 1;
|
||||
if (size == 0) // a structure cannot have size 0
|
||||
size = 1;
|
||||
size += maxAlignment - (size - 1) % maxAlignment - 1;
|
||||
return new SizeAndAlignment(size, maxAlignment);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue