Skip to content

Commit ab6b15e

Browse files
committed
fix(templates): Corrected explicit template instantiations to avoid multiple instances.
1 parent 7297033 commit ab6b15e

13 files changed

+225
-36
lines changed

Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
#include "Poco/Data/ODBC/ODBC.h"
22+
#include "Poco/Data/ODBC/Utility.h"
2223
#include <vector>
2324
#include <cstring>
2425
#ifdef POCO_OS_FAMILY_WINDOWS
@@ -243,10 +244,19 @@ class Diagnostics
243244

244245
// explicit instantiation definition
245246
#ifndef POCO_DOC
246-
template class Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
247-
template class Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
248-
template class Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
249-
template class Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
247+
248+
#if defined(POCO_OS_FAMILY_WINDOWS)
249+
extern template class Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
250+
extern template class Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
251+
extern template class Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
252+
extern template class Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
253+
#else
254+
extern template class ODBC_API Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
255+
extern template class ODBC_API Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
256+
extern template class ODBC_API Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
257+
extern template class ODBC_API Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
258+
#endif
259+
250260
#endif
251261

252262

Data/ODBC/include/Poco/Data/ODBC/Error.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,20 @@ class Error
126126

127127
// explicit instantiation definition
128128
#ifndef POCO_DOC
129-
template class Error<SQLHENV, SQL_HANDLE_ENV>;
130-
template class Error<SQLHDBC, SQL_HANDLE_DBC>;
131-
template class Error<SQLHSTMT, SQL_HANDLE_STMT>;
132-
template class Error<SQLHDESC, SQL_HANDLE_DESC>;
129+
130+
#if defined(POCO_OS_FAMILY_WINDOWS)
131+
extern template class Error<SQLHENV, SQL_HANDLE_ENV>;
132+
extern template class Error<SQLHDBC, SQL_HANDLE_DBC>;
133+
extern template class Error<SQLHSTMT, SQL_HANDLE_STMT>;
134+
extern template class Error<SQLHDESC, SQL_HANDLE_DESC>;
135+
#else
136+
extern template class ODBC_API Error<SQLHENV, SQL_HANDLE_ENV>;
137+
extern template class ODBC_API Error<SQLHDBC, SQL_HANDLE_DBC>;
138+
extern template class ODBC_API Error<SQLHSTMT, SQL_HANDLE_STMT>;
139+
extern template class ODBC_API Error<SQLHDESC, SQL_HANDLE_DESC>;
133140
#endif
134141

142+
#endif
135143

136144
using EnvironmentError = Error<SQLHENV, SQL_HANDLE_ENV>;
137145
using ConnectionError = Error<SQLHDBC, SQL_HANDLE_DBC>;

Data/ODBC/include/Poco/Data/ODBC/ODBCException.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,19 @@ class HandleException: public ODBCException
140140

141141
// explicit instantiation definition
142142
#ifndef POCO_DOC
143-
template class HandleException<SQLHENV, SQL_HANDLE_ENV>;
144-
template class HandleException<SQLHDBC, SQL_HANDLE_DBC>;
145-
template class HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
146-
template class HandleException<SQLHDESC, SQL_HANDLE_DESC>;
143+
144+
#if defined(POCO_OS_FAMILY_WINDOWS)
145+
extern template class HandleException<SQLHENV, SQL_HANDLE_ENV>;
146+
extern template class HandleException<SQLHDBC, SQL_HANDLE_DBC>;
147+
extern template class HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
148+
extern template class HandleException<SQLHDESC, SQL_HANDLE_DESC>;
149+
#else
150+
extern template class ODBC_API HandleException<SQLHENV, SQL_HANDLE_ENV>;
151+
extern template class ODBC_API HandleException<SQLHDBC, SQL_HANDLE_DBC>;
152+
extern template class ODBC_API HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
153+
extern template class ODBC_API HandleException<SQLHDESC, SQL_HANDLE_DESC>;
154+
#endif
155+
147156
#endif
148157

149158

Data/ODBC/src/Diagnostics.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Diagnostics.cpp
3+
//
4+
// Library: Data/ODBC
5+
// Package: ODBC
6+
// Module: Diagnostics
7+
//
8+
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
9+
// and Contributors.
10+
//
11+
// SPDX-License-Identifier: BSL-1.0
12+
//
13+
14+
15+
#include "Poco/Data/ODBC/Diagnostics.h"
16+
17+
18+
namespace Poco {
19+
namespace Data {
20+
namespace ODBC {
21+
22+
// explicit instantiation definition
23+
#ifndef POCO_DOC
24+
25+
#if defined(POCO_OS_FAMILY_WINDOWS)
26+
template class ODBC_API Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
27+
template class ODBC_API Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
28+
template class ODBC_API Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
29+
template class ODBC_API Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
30+
#else
31+
template class Diagnostics<SQLHENV, SQL_HANDLE_ENV>;
32+
template class Diagnostics<SQLHDBC, SQL_HANDLE_DBC>;
33+
template class Diagnostics<SQLHSTMT, SQL_HANDLE_STMT>;
34+
template class Diagnostics<SQLHDESC, SQL_HANDLE_DESC>;
35+
#endif
36+
37+
#endif
38+
39+
40+
} } } // namespace Poco::Data::ODBC

Data/ODBC/src/Error.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Error.cpp
3+
//
4+
// Library: Data/ODBC
5+
// Package: ODBC
6+
// Module: Error
7+
//
8+
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
9+
// and Contributors.
10+
//
11+
// SPDX-License-Identifier: BSL-1.0
12+
//
13+
14+
15+
#include "Poco/Data/ODBC/Error.h"
16+
17+
18+
namespace Poco {
19+
namespace Data {
20+
namespace ODBC {
21+
22+
// explicit instantiation definition
23+
#ifndef POCO_DOC
24+
25+
#if defined(POCO_OS_FAMILY_WINDOWS)
26+
template class ODBC_API Error<SQLHENV, SQL_HANDLE_ENV>;
27+
template class ODBC_API Error<SQLHDBC, SQL_HANDLE_DBC>;
28+
template class ODBC_API Error<SQLHSTMT, SQL_HANDLE_STMT>;
29+
template class ODBC_API Error<SQLHDESC, SQL_HANDLE_DESC>;
30+
#else
31+
template class Error<SQLHENV, SQL_HANDLE_ENV>;
32+
template class Error<SQLHDBC, SQL_HANDLE_DBC>;
33+
template class Error<SQLHSTMT, SQL_HANDLE_STMT>;
34+
template class Error<SQLHDESC, SQL_HANDLE_DESC>;
35+
#endif
36+
37+
#endif
38+
39+
40+
} } } // namespace Poco::Data::ODBC

Data/ODBC/src/ODBCException.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ namespace Poco {
2020
namespace Data {
2121
namespace ODBC {
2222

23+
#if defined(POCO_OS_FAMILY_WINDOWS)
24+
template class ODBC_API HandleException<SQLHENV, SQL_HANDLE_ENV>;
25+
template class ODBC_API HandleException<SQLHDBC, SQL_HANDLE_DBC>;
26+
template class ODBC_API HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
27+
template class ODBC_API HandleException<SQLHDESC, SQL_HANDLE_DESC>;
28+
#else
29+
template class HandleException<SQLHENV, SQL_HANDLE_ENV>;
30+
template class HandleException<SQLHDBC, SQL_HANDLE_DBC>;
31+
template class HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
32+
template class HandleException<SQLHDESC, SQL_HANDLE_DESC>;
33+
#endif
2334

2435
POCO_IMPLEMENT_EXCEPTION(ODBCException, Poco::Data::DataException, "Generic ODBC error")
2536
POCO_IMPLEMENT_EXCEPTION(InsufficientStorageException, ODBCException, "Insufficient storage error")

Foundation/include/Poco/BufferedBidirectionalStreamBuf.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,14 @@ class BasicBufferedBidirectionalStreamBuf: public std::basic_streambuf<ch, tr>
181181
//
182182
// We provide an instantiation for char.
183183
//
184-
// Visual C++ needs a workaround - explicitly importing the template
185-
// instantiation - to avoid duplicate symbols due to multiple
186-
// instantiations in different libraries.
187-
//
188-
#if defined(_MSC_VER) && defined(POCO_DLL) && !defined(Foundation_EXPORTS)
189-
template class Foundation_API BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
184+
185+
#if defined(POCO_OS_FAMILY_WINDOWS)
186+
extern template class BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
187+
#else
188+
extern template class Foundation_API BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
190189
#endif
191-
using BufferedBidirectionalStreamBuf
192-
= BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
190+
191+
using BufferedBidirectionalStreamBuf = BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
193192

194193
} // namespace Poco
195194

Foundation/include/Poco/BufferedStreamBuf.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,17 @@ class BasicBufferedStreamBuf: public std::basic_streambuf<ch, tr>
160160
BasicBufferedStreamBuf& operator = (const BasicBufferedStreamBuf&);
161161
};
162162

163-
164163
//
165164
// We provide an instantiation for char.
166165
//
167-
// Visual C++ needs a workaround - explicitly importing the template
168-
// instantiation - to avoid duplicate symbols due to multiple
169-
// instantiations in different libraries.
170-
//
171-
#if defined(_MSC_VER) && defined(POCO_DLL) && !defined(Foundation_EXPORTS)
172-
template class Foundation_API BasicBufferedStreamBuf<char, std::char_traits<char>>;
166+
167+
#if defined(POCO_OS_FAMILY_WINDOWS)
168+
extern template class BasicBufferedStreamBuf<char, std::char_traits<char>>;
169+
#else
170+
extern template class Foundation_API BasicBufferedStreamBuf<char, std::char_traits<char>>;
173171
#endif
174-
typedef BasicBufferedStreamBuf<char, std::char_traits<char>> BufferedStreamBuf;
172+
173+
using BufferedStreamBuf = BasicBufferedStreamBuf<char, std::char_traits<char>>;
175174

176175

177176
} // namespace Poco

Foundation/include/Poco/UnbufferedStreamBuf.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ class BasicUnbufferedStreamBuf: public std::basic_streambuf<ch, tr>
163163
//
164164
// We provide an instantiation for char.
165165
//
166-
// Visual C++ needs a workaround - explicitly importing the template
167-
// instantiation - to avoid duplicate symbols due to multiple
168-
// instantiations in different libraries.
169-
//
170-
#if defined(_MSC_VER) && defined(POCO_DLL) && !defined(Foundation_EXPORTS)
171-
template class Foundation_API BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
166+
167+
#if defined(POCO_OS_FAMILY_WINDOWS)
168+
extern template class BasicUnBufferedStreamBuf<char, std::char_traits<char>>;
169+
#else
170+
extern template class Foundation_API BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
172171
#endif
173-
typedef BasicUnbufferedStreamBuf<char, std::char_traits<char>> UnbufferedStreamBuf;
174172

173+
using UnbufferedStreamBuf = BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
175174

176175
} // namespace Poco
177176

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// BufferedBidirectionalStreamBuf.cpp
3+
//
4+
// Library: Foundation
5+
// Package: Streams
6+
// Module: StreamBuf
7+
//
8+
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
9+
// and Contributors.
10+
//
11+
// SPDX-License-Identifier: BSL-1.0
12+
//
13+
14+
15+
#include "Poco/BufferedBidirectionalStreamBuf.h"
16+
17+
namespace Poco {
18+
19+
#if defined(POCO_OS_FAMILY_WINDOWS)
20+
template class Foundation_API BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
21+
#else
22+
template class BasicBufferedBidirectionalStreamBuf<char, std::char_traits<char>>;
23+
#endif
24+
25+
}

Foundation/src/BufferedStreamBuf.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// BufferedStreamBuf.cpp
3+
//
4+
// Library: Foundation
5+
// Package: Streams
6+
// Module: StreamBuf
7+
//
8+
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
9+
// and Contributors.
10+
//
11+
// SPDX-License-Identifier: BSL-1.0
12+
//
13+
14+
15+
#include "Poco/BufferedStreamBuf.h"
16+
17+
namespace Poco {
18+
19+
#if defined(POCO_OS_FAMILY_WINDOWS)
20+
template class Foundation_API BasicBufferedStreamBuf<char, std::char_traits<char>>;
21+
#else
22+
template class BasicBufferedStreamBuf<char, std::char_traits<char>>;
23+
#endif
24+
25+
}

Foundation/src/FileStream.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
#include "Poco/FileStream.h"
16-
#include "Poco/Exception.h"
1716
#if defined(POCO_OS_FAMILY_WINDOWS)
1817
#include "FileStream_WIN32.cpp"
1918
#else
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// UnbufferedStreamBuf.cpp
3+
//
4+
// Library: Foundation
5+
// Package: Streams
6+
// Module: StreamBuf
7+
//
8+
// Copyright (c) 2025, Applied Informatics Software Engineering GmbH.
9+
// and Contributors.
10+
//
11+
// SPDX-License-Identifier: BSL-1.0
12+
//
13+
14+
15+
#include "Poco/UnbufferedStreamBuf.h"
16+
17+
namespace Poco {
18+
19+
#if defined(POCO_OS_FAMILY_WINDOWS)
20+
template class Foundation_API BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
21+
#else
22+
template class BasicUnbufferedStreamBuf<char, std::char_traits<char>>;
23+
#endif
24+
25+
}

0 commit comments

Comments
 (0)