ridiculousfish / libdivide

Official git repository for libdivide: optimized integer division
http://libdivide.com
Other
1.1k stars 79 forks source link

Replace anonymous namespace with inline specifiers #54

Closed moskupols closed 5 years ago

moskupols commented 5 years ago

Hi, I've noticed that in the C++ version we place everything inside anonymous namespace. While this theoretically makes it easy to maintain header-only design, I believe this actually makes any use of libdivide::divider in a multi-file project potentially ill-defined. The problem is that, as each translation unit has its own anonymous namespace, in each translation unit we declare a unique class template libdivide::::divide, so we cannot really pass an instance of divider between translation unit.

g++ agrees that something is wrong with this approach by issuing a warning similar to

warning: ‘IntWithDivider’ has a field ‘IntWithDivider::divider’ whose type uses the anonymous namespace [-Wsubobject-linkage]
 struct IntWithDivider {
        ^~~~~~~~~~~~~~

In this pull request I try to address this issue by placing everything in the common libdivide:: namespace, and providing every function with inline specifier.

ridiculousfish commented 5 years ago

Thanks!!