Thursday, 12 September 2013

Problems with static_assert(sizeof(X)) upgrading to VS 2013

While upgrading to VS 2013 I encountered several changes to sizeof classes which stopped me from compiling:

static_assert(sizeof(QESQLSelect) == 188, "You probably have more cloning to do?");

Presumably stl has changed it's implementation so the sizes are different between versions.

The link below shows how to change compile options to show the sizeof to use.
http://blogs.msdn.com/b/vcblog/archive/2007/05/17/diagnosing-hidden-odr-violations-in-visual-c-and-fixing-lnk2022.aspx

Summary:
Add the following option and compile your cpp.  (Remember to remove the option afterwards)
I also used this option in the past to reduce the memory usage of my application.

This produces the following in the output window:

class QESQLSelect size(164):
+---
| +--- (base class QESQLSelectBase)
0 | | {vfptr}
| +---
4 | m_bCheckDistinctColumns
| <alignment member> (size=3)
8 | m_nDBType
12 | m_bDistinct
| <alignment member> (size=3)
16 | m_nTopN
20 | m_bHasImplicitOrdering
21 | m_bCount
| <alignment member> (size=2)
24 | QESQLColumnList m_selectedColumns
40 | ?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@ m_strTableOrAliasName
44 | m_pAlternativeSQLSuffix
48 | m_pOptionalSubQuery
52 | ?$auto_vector@PAVQESQLJoinCondition@@ m_joinConditions
68 | ?$auto_vector@PAVQESQLCrossApplyCondition@@ m_crossApplyConditions
84 | ?$auto_vector@PAVQESQLWhereCondition@@ m_whereConditions
100 | ?$auto_vector@PAVQESQLHavingCondition@@ m_havingConditions
116 | m_pGroupBy
120 | DimensionalRollupType m_RollupType
124 | m_pOrderBy
128 | m_pWithSelect
132 | m_pConnectPrior
136 | ?$vector@V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@V?$allocator@V?$CStringT@_WV?StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@std@@ m_vecOracleHints
152 | m_pVecSQLServerHints
156 | ?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@ m_strComment
160 | ?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@ m_strSimpleTableAlias
+---

 
So I know to change the code to:
static_assert(sizeof(QESQLSelect) == 164, "You probably have more cloning to do?"); 

Note as of VS 2017 the flag seems to have been removed however d1ReportAllClassLayout still works.
Note again - it's a capitalisation problem.. use /d1reportSingleClassLayout

No comments:

Post a Comment