View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0011158ITKpublic2010-08-23 09:012011-06-26 20:46
ReporterHans Johnson 
Assigned ToHans Johnson 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusassignedResolutionopen 
PlatformOSOS Version
Product VersionITK-4-A2 
Target VersionFixed in Version 
Summary0011158: Explicit instantiation and itkStaticConstMacro are not properly implemented
DescriptionThe itkStaticConstMacro does not appear to create static member functions in a way that is compliant with explicit instantiation.

It also appears that in all cases, the itkStaticConstMacro is only used on types that can also be enumerations. Furthermore, previous 3.20 and earlier releases ALWAYS used enumerations instead of "static const unsigned int", and this is why explicit instantiations worked previously.

A review of Explicit instantiation needs to occur to determine what the proper strategy is.
TagsNo tags attached.
Resolution Date
Sprint
Sprint Status
Attached Files

 Relationships

  Notes
(0021892)
Hans Johnson (developer)
2010-08-23 09:27

It appears that initialization of templated static const variables is a feature that is new in C++0x with the new constexpr keyword.


Intiailization of static const variables still apears to be necessary OUTSIDE the class definition.

All examples referencing this class of problem indicate a solution similar to:

http://www.velocityreviews.com/forums/t458125-template-class-and-static-member-variables.html [^]
(0021906)
Hans Johnson (developer)
2010-08-23 18:35

Further code review indicates that itkStaticConstMacro is used only for "unsigned int" and a few "bool" types.

Using the non-enumeration variant of itkStaticConstMacro requires separate declaration and initialization of the variables for explicit instantiation to work properly.

http://stackoverflow.com/questions/1563897/c-static-constant-string-class-member [^]

====
Bjarne Stroustrup's C++ Style and Technique FAQ
From : http://www2.research.att.com/~bs/bs_faq2.html [^]
"How do I define an in-class constant?"
(0021907)
Hans Johnson (developer)
2010-08-23 18:40

You can reference the static const variables in other compilation units (i.e. in the explicitly instantiated units) if (and only if) it has an out-of-class definition.

The "initialization" occurs inside the class, but the definition of the variables existence MUST occur outside the class.

template <class PixelType, unsigned int Dimension> const unsigned int itk::Image<PixelType,Dimension>::ImageDimension;
(0021915)
Bradley Lowekamp (developer)
2010-08-24 07:11

Only alternative I can think of is inline static member functions.
(0021929)
Brad King (manager)
2010-08-24 14:32

From C++98 9.4.2/4:

"If a static data member is of const integral or const enumeration
 type, its declaration in the class definition can specify a
 constant-initializer which shall be an integral constant
 expression (5.19). In that case, the member can appear in
 integral constant expressions within its scope. The member shall
 still be defined in a namespace scope if it is used in the
 program and the namespace scope definition shall not contain an
 initializer."

This means that if the member is used only as an "integral constant expression" then it does not need a definition because it is used only at compile time. However, if it is "used in the program" then it needs a definition. This is the case for example when the address of the member is taken. On Windows the dllexport caused by explicit instantiation may also require the definition.

Can you produce a minimal example (separate from ITK) that shows this?
(0026980)
Hans Johnson (developer)
2011-06-26 20:46

This works as is, but may cause problems for explicit instantiation. Since explicit instantiation is not currently being worked on, this will likely not raise high enough to warrant further investigation.

 Issue History
Date Modified Username Field Change
2010-08-23 09:01 Hans Johnson New Issue
2010-08-23 09:27 Hans Johnson Note Added: 0021892
2010-08-23 18:35 Hans Johnson Note Added: 0021906
2010-08-23 18:40 Hans Johnson Note Added: 0021907
2010-08-23 19:56 Bradley Lowekamp Note Added: 0021908
2010-08-23 19:57 Bradley Lowekamp Note Edited: 0021908
2010-08-23 19:59 Bradley Lowekamp Note Deleted: 0021908
2010-08-24 07:11 Bradley Lowekamp Note Added: 0021915
2010-08-24 14:32 Brad King Note Added: 0021929
2010-10-12 22:21 Hans Johnson Status new => assigned
2010-10-12 22:21 Hans Johnson Assigned To => Hans Johnson
2011-06-26 20:46 Hans Johnson Note Added: 0026980


Copyright © 2000 - 2018 MantisBT Team