Skip to content

Commit a2635e1

Browse files
authored
Use the standard nothrow tag instead of our own type (#101811)
1 parent 7cde9aa commit a2635e1

File tree

8 files changed

+24
-50
lines changed

8 files changed

+24
-50
lines changed

src/coreclr/debug/ee/debugger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,7 +3613,7 @@ inline void * __cdecl operator new[](size_t n, const InteropSafe&)
36133613
return result;
36143614
}
36153615

3616-
inline void * __cdecl operator new(size_t n, const InteropSafe&, const NoThrow&) throw()
3616+
inline void * __cdecl operator new(size_t n, const InteropSafe&, const std::nothrow_t&) noexcept
36173617
{
36183618
CONTRACTL
36193619
{
@@ -3632,7 +3632,7 @@ inline void * __cdecl operator new(size_t n, const InteropSafe&, const NoThrow&)
36323632
return result;
36333633
}
36343634

3635-
inline void * __cdecl operator new[](size_t n, const InteropSafe&, const NoThrow&) throw()
3635+
inline void * __cdecl operator new[](size_t n, const InteropSafe&, const std::nothrow_t&) noexcept
36363636
{
36373637
CONTRACTL
36383638
{

src/coreclr/inc/new.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@
77
#ifndef __new__hpp
88
#define __new__hpp
99

10-
#if defined(_MSC_VER) && _MSC_VER < 1900
11-
#define NOEXCEPT
12-
#else
13-
#define NOEXCEPT noexcept
14-
#endif
15-
16-
struct NoThrow { int x; };
17-
extern const NoThrow nothrow;
10+
#include <new>
1811

19-
void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT;
20-
void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT;
12+
using std::nothrow;
2113

2214
#ifdef _DEBUG
2315
void DisableThrowCheck();

src/coreclr/inc/stresslog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ class ThreadStressLog {
807807
#endif //!STRESS_LOG_READONLY && !STRESS_LOG_ANALYZER
808808

809809
#if defined(MEMORY_MAPPED_STRESSLOG) && !defined(STRESS_LOG_ANALYZER)
810-
void* __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT;
810+
void* __cdecl operator new(size_t n, const std::nothrow_t&) noexcept;
811811
void __cdecl operator delete (void * chunk);
812812
#endif
813813

src/coreclr/inc/utilcode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ _Ret_bytecap_(n) void * __cdecl
316316
operator new[](size_t n);
317317

318318
void __cdecl
319-
operator delete(void *p) NOEXCEPT;
319+
operator delete(void *p) noexcept;
320320

321321
void __cdecl
322-
operator delete[](void *p) NOEXCEPT;
322+
operator delete[](void *p) noexcept;
323323

324324
#ifdef _DEBUG_IMPL
325325
HRESULT _OutOfMemory(LPCSTR szFile, int iLine);
@@ -3728,8 +3728,8 @@ extern const CExecutable executable;
37283728

37293729
void * __cdecl operator new(size_t n, const CExecutable&);
37303730
void * __cdecl operator new[](size_t n, const CExecutable&);
3731-
void * __cdecl operator new(size_t n, const CExecutable&, const NoThrow&);
3732-
void * __cdecl operator new[](size_t n, const CExecutable&, const NoThrow&);
3731+
void * __cdecl operator new(size_t n, const CExecutable&, const std::nothrow_t&) noexcept;
3732+
void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t&) noexcept;
37333733

37343734

37353735
//

src/coreclr/utilcode/clrhost_nodependencies.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,8 @@ ClrDebugState *CLRInitDebugState()
202202

203203
#endif //defined(_DEBUG_IMPL) && defined(ENABLE_CONTRACTS_IMPL)
204204

205-
const NoThrow nothrow = { 0 };
206-
207-
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
208-
// use standard heap functions for address sanitizer
209-
#else
210-
205+
// use standard heap functions for AddressSanitizer and for the DAC build.
206+
#if !defined(HAS_ADDRESS_SANITIZER) && !defined(DACCESS_COMPILE)
211207
#ifdef _DEBUG
212208
#ifdef TARGET_X86
213209
#define OS_HEAP_ALIGN 8
@@ -221,7 +217,7 @@ const NoThrow nothrow = { 0 };
221217
static HANDLE g_hProcessHeap;
222218
#endif
223219

224-
FORCEINLINE void* ClrMalloc(size_t size)
220+
static FORCEINLINE void* ClrMalloc(size_t size)
225221
{
226222
STATIC_CONTRACT_NOTHROW;
227223

@@ -339,14 +335,9 @@ operator new[](size_t n)
339335
return result;
340336
};
341337

342-
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
343338

344-
void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT
339+
void * __cdecl operator new(size_t n, const std::nothrow_t&) noexcept
345340
{
346-
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
347-
// use standard heap functions for address sanitizer (which doesn't provide for NoThrow)
348-
void * result = operator new(n);
349-
#else
350341
STATIC_CONTRACT_NOTHROW;
351342
STATIC_CONTRACT_GC_NOTRIGGER;
352343
STATIC_CONTRACT_FAULT;
@@ -355,17 +346,12 @@ void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT
355346
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));
356347

357348
void* result = ClrMalloc(n);
358-
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
359349
TRASH_LASTERROR;
360350
return result;
361351
}
362352

363-
void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT
353+
void * __cdecl operator new[](size_t n, const std::nothrow_t&) noexcept
364354
{
365-
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
366-
// use standard heap functions for address sanitizer (which doesn't provide for NoThrow)
367-
void * result = operator new[](n);
368-
#else
369355
STATIC_CONTRACT_NOTHROW;
370356
STATIC_CONTRACT_GC_NOTRIGGER;
371357
STATIC_CONTRACT_FAULT;
@@ -374,16 +360,12 @@ void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT
374360
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));
375361

376362
void* result = ClrMalloc(n);
377-
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
378363
TRASH_LASTERROR;
379364
return result;
380365
}
381366

382-
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
383-
// use standard heap functions for address sanitizer
384-
#else
385367
void __cdecl
386-
operator delete(void *p) NOEXCEPT
368+
operator delete(void *p) noexcept
387369
{
388370
STATIC_CONTRACT_NOTHROW;
389371
STATIC_CONTRACT_GC_NOTRIGGER;
@@ -395,7 +377,7 @@ operator delete(void *p) NOEXCEPT
395377
}
396378

397379
void __cdecl
398-
operator delete[](void *p) NOEXCEPT
380+
operator delete[](void *p) noexcept
399381
{
400382
STATIC_CONTRACT_NOTHROW;
401383
STATIC_CONTRACT_GC_NOTRIGGER;
@@ -405,7 +387,7 @@ operator delete[](void *p) NOEXCEPT
405387
TRASH_LASTERROR;
406388
}
407389

408-
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
390+
#endif // !HAS_ADDRESS_SANITIZER && !DACCESS_COMPILE
409391

410392
/* ------------------------------------------------------------------------ *
411393
* New operator overloading for the executable heap
@@ -494,7 +476,7 @@ void * __cdecl operator new[](size_t n, const CExecutable&)
494476
return result;
495477
}
496478

497-
void * __cdecl operator new(size_t n, const CExecutable&, const NoThrow&)
479+
void * __cdecl operator new(size_t n, const CExecutable&, const std::nothrow_t&) noexcept
498480
{
499481
STATIC_CONTRACT_NOTHROW;
500482
STATIC_CONTRACT_GC_NOTRIGGER;
@@ -511,7 +493,7 @@ void * __cdecl operator new(size_t n, const CExecutable&, const NoThrow&)
511493
return result;
512494
}
513495

514-
void * __cdecl operator new[](size_t n, const CExecutable&, const NoThrow&)
496+
void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t&) noexcept
515497
{
516498
STATIC_CONTRACT_NOTHROW;
517499
STATIC_CONTRACT_GC_NOTRIGGER;

src/coreclr/utilcode/stresslog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ void* StressLog::AllocMemoryMapped(size_t n)
963963
return nullptr;
964964
}
965965

966-
void* __cdecl ThreadStressLog::operator new(size_t n, const NoThrow&) NOEXCEPT
966+
void* __cdecl ThreadStressLog::operator new(size_t n, const std::nothrow_t&) noexcept
967967
{
968968
if (StressLogChunk::s_memoryMapped)
969969
return StressLog::AllocMemoryMapped(n);

src/coreclr/vm/stackingallocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ void * __cdecl operator new[](size_t n, StackingAllocator * alloc)
399399
return retval;
400400
}
401401

402-
void * __cdecl operator new(size_t n, StackingAllocator * alloc, const NoThrow&) throw()
402+
void * __cdecl operator new(size_t n, StackingAllocator * alloc, const std::nothrow_t&) noexcept
403403
{
404404
STATIC_CONTRACT_NOTHROW;
405405
STATIC_CONTRACT_FAULT;
@@ -412,7 +412,7 @@ void * __cdecl operator new(size_t n, StackingAllocator * alloc, const NoThrow&)
412412
return alloc->UnsafeAllocNoThrow((unsigned)n);
413413
}
414414

415-
void * __cdecl operator new[](size_t n, StackingAllocator * alloc, const NoThrow&) throw()
415+
void * __cdecl operator new[](size_t n, StackingAllocator * alloc, const std::nothrow_t&) noexcept
416416
{
417417
STATIC_CONTRACT_NOTHROW;
418418
STATIC_CONTRACT_FAULT;

src/coreclr/vm/stackingallocator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ class StackingAllocatorHolder
271271

272272
void * __cdecl operator new(size_t n, StackingAllocator *alloc);
273273
void * __cdecl operator new[](size_t n, StackingAllocator *alloc);
274-
void * __cdecl operator new(size_t n, StackingAllocator *alloc, const NoThrow&) throw();
275-
void * __cdecl operator new[](size_t n, StackingAllocator *alloc, const NoThrow&) throw();
274+
void * __cdecl operator new(size_t n, StackingAllocator *alloc, const std::nothrow_t&) noexcept;
275+
void * __cdecl operator new[](size_t n, StackingAllocator *alloc, const std::nothrow_t&) noexcept;
276276

277277
#ifdef _MSC_VER
278278
#pragma warning(pop)

0 commit comments

Comments
 (0)