浏览代码

Clang identifies some functions as "noreturn" + one noexcept(false)

Source commit: fc0c35fdddcd50a10d9ca13fc515164885325f81
Martin Prikryl 7 月之前
父节点
当前提交
7b54dde3a6

+ 2 - 2
source/core/Common.cpp

@@ -4524,13 +4524,13 @@ UnicodeString GetAncestorProcessNames()
   return AncestorProcessNames;
 }
 //---------------------------------------------------------------------------
-void NotImplemented()
+NORETURN void NotImplemented()
 {
   DebugFail();
   throw Exception(L"Not implemented");
 }
 //---------------------------------------------------------------------------
-void NotSupported()
+NORETURN void NotSupported()
 {
   throw Exception(MainInstructions(LoadStr(NOTSUPPORTED)));
 }

+ 3 - 4
source/core/Common.h

@@ -3,6 +3,7 @@
 #define CommonH
 //---------------------------------------------------------------------------
 #include <vector>
+#include "Global.h"
 //---------------------------------------------------------------------------
 #define EXCEPTION throw ExtException(NULL, L"")
 #define THROWOSIFFALSE(C) { if (!(C)) RaiseLastOSError(); }
@@ -206,8 +207,8 @@ UnicodeString GetEnvironmentInfo();
 void SetStringValueEvenIfEmpty(TStrings * Strings, const UnicodeString & Name, const UnicodeString & Value);
 UnicodeString __fastcall GetAncestorProcessName(int Levels = 1);
 UnicodeString GetAncestorProcessNames();
-void NotSupported();
-void NotImplemented();
+NORETURN void NotSupported();
+NORETURN void NotImplemented();
 UnicodeString GetDividerLine();
 TStrings * ProcessFeatures(TStrings * Features, const UnicodeString & FeaturesOverride);
 //---------------------------------------------------------------------------
@@ -353,8 +354,6 @@ UnicodeString __fastcall AssemblyAddRawSettings(
   TAssemblyLanguage Language, TStrings * RawSettings, const UnicodeString & ClassName,
   const UnicodeString & MethodName);
 //---------------------------------------------------------------------------
-#include "Global.h"
-//---------------------------------------------------------------------------
 template<class T>
 class TValueRestorer
 {

+ 1 - 1
source/core/Cryptography.cpp

@@ -735,7 +735,7 @@ TEncryption::TEncryption(const RawByteString & Key)
   }
 }
 //---------------------------------------------------------------------------
-TEncryption::~TEncryption()
+TEncryption::~TEncryption() EXCEPT
 {
   if (FContext != NULL)
   {

+ 1 - 1
source/core/Cryptography.h

@@ -25,7 +25,7 @@ class TEncryption
 {
 public:
   TEncryption(const RawByteString & Key);
-  ~TEncryption();
+  ~TEncryption() EXCEPT;
 
   static bool IsEncryptedFileName(const UnicodeString & FileName);
 

+ 1 - 1
source/core/FileMasks.cpp

@@ -516,7 +516,7 @@ bool __fastcall TFileMasks::operator ==(const UnicodeString & rhs) const
   return (Masks == rhs);
 }
 //---------------------------------------------------------------------------
-void __fastcall TFileMasks::ThrowError(int Start, int End)
+NORETURN void __fastcall TFileMasks::ThrowError(int Start, int End)
 {
   throw EFileMasksException(
     FMTLOAD(MASK_ERROR, (Masks.SubString(Start, End - Start + 1))),

+ 2 - 1
source/core/FileMasks.h

@@ -4,6 +4,7 @@
 //---------------------------------------------------------------------------
 #include <vector>
 #include <Masks.hpp>
+#include <Global.h>
 //---------------------------------------------------------------------------
 class EFileMasksException : public Exception
 {
@@ -125,7 +126,7 @@ private:
     const UnicodeString & Path, const TParams * Params, const TMasks & Masks, bool Recurse);
   static inline bool MatchesMaskMask(TMask::TKind MaskKind, Masks::TMask * MaskMask, const UnicodeString & Str);
   static Masks::TMask * DoCreateMaskMask(const UnicodeString & Str);
-  void __fastcall ThrowError(int Start, int End);
+  NORETURN void __fastcall ThrowError(int Start, int End);
   bool DoMatches(
     const UnicodeString & FileName, bool Local, bool Directory, const UnicodeString & Path, const TParams * Params,
     bool RecurseInclude, bool & ImplicitMatch) const;

+ 2 - 2
source/core/FileSystems.cpp

@@ -21,13 +21,13 @@ __fastcall TCustomFileSystem::~TCustomFileSystem()
 UnicodeString __fastcall TCustomFileSystem::GetHomeDirectory()
 {
   NotImplemented();
-  return EmptyStr;
+  UNREACHABLE_AFTER_NORETURN(return EmptyStr);
 }
 //---------------------------------------------------------------------------
 UnicodeString TCustomFileSystem::CalculateFilesChecksumInitialize(const UnicodeString & DebugUsedArg(Alg))
 {
   NotImplemented();
-  return EmptyStr;
+  UNREACHABLE_AFTER_NORETURN(return EmptyStr);
 }
 //---------------------------------------------------------------------------
 void __fastcall TCustomFileSystem::TransferOnDirectory(

+ 6 - 0
source/core/Global.h

@@ -36,8 +36,14 @@ private:
 //---------------------------------------------------------------------------
 #ifdef __clang__
 #define CLANG_INITIALIZE(V) = (V)
+#define NORETURN [[noreturn]]
+#define UNREACHABLE_AFTER_NORETURN(STATEMENT)
+#define EXCEPT noexcept(false)
 #else
 #define CLANG_INITIALIZE(V)
+#define NORETURN
+#define UNREACHABLE_AFTER_NORETURN(STATEMENT) STATEMENT
+#define EXCEPT
 #endif
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------

+ 1 - 1
source/core/HierarchicalStorage.cpp

@@ -1929,7 +1929,7 @@ bool __fastcall TOptionsIniFile::AllowWrite()
 
     case wmFail:
       NotImplemented();
-      return false; // never gets here
+      UNREACHABLE_AFTER_NORETURN(return false);
 
     case wmIgnore:
       return false;

+ 1 - 1
source/core/PuttyIntf.cpp

@@ -338,7 +338,7 @@ size_t banner(Seat * seat, const void * data, size_t len)
   return 0; // PuTTY never uses the value
 }
 //---------------------------------------------------------------------------
-static void SSHFatalError(const char * Format, va_list Param)
+NORETURN static void SSHFatalError(const char * Format, va_list Param)
 {
   char Buf[200];
   vsnprintf(Buf, LENOF(Buf), Format, Param);

+ 1 - 1
source/core/RemoteFiles.cpp

@@ -2977,7 +2977,7 @@ TStrings * TSynchronizeChecklist::TItem::GetFileList() const
     default:
       DebugFail();
       NotImplemented();
-      break;
+      UNREACHABLE_AFTER_NORETURN(break);
   }
   return FileList.release();
 }

+ 3 - 3
source/core/ScpFileSystem.cpp

@@ -663,7 +663,7 @@ void __fastcall TSCPFileSystem::ReadCommandOutput(int Params, const UnicodeStrin
   }
 }
 //---------------------------------------------------------------------------
-void TSCPFileSystem::InvalidOutputError(const UnicodeString & Command)
+NORETURN void TSCPFileSystem::InvalidOutputError(const UnicodeString & Command)
 {
   FTerminal->TerminalError(FMTLOAD(INVALID_OUTPUT_ERROR, (Command, Output->Text)));
 }
@@ -2536,7 +2536,7 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
           case 2:
             // Fatal error, terminate copying
             FTerminal->TerminalError(Line);
-            return; // Unreachable
+            UNREACHABLE_AFTER_NORETURN(return);
 
           case L'E': // Exit
             FSecureShell->SendNull();
@@ -2713,7 +2713,7 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
               {
                 // In this step we can still cancel transfer, so we do it
                 SCPError(E.Message, false);
-                throw;
+                UNREACHABLE_AFTER_NORETURN(throw);
               }
 
               // We succeeded, so we confirm transfer to remote side

+ 2 - 2
source/core/ScpFileSystem.h

@@ -116,13 +116,13 @@ private:
   void __fastcall EnsureLocation();
   void __fastcall ExecCommand(TFSCommand Cmd, const TVarRec * args = NULL,
     int size = 0, int Params = -1);
-  void InvalidOutputError(const UnicodeString & Command);
+  NORETURN void InvalidOutputError(const UnicodeString & Command);
   void __fastcall ReadCommandOutput(int Params, const UnicodeString * Cmd = NULL);
   void __fastcall SCPResponse(bool * GotLastLine = NULL);
   void __fastcall SCPDirectorySource(const UnicodeString DirectoryName,
     const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params,
     TFileOperationProgressType * OperationProgress, int Level);
-  void __fastcall SCPError(const UnicodeString Message, bool Fatal);
+  NORETURN void __fastcall SCPError(const UnicodeString Message, bool Fatal);
   void __fastcall SCPSendError(const UnicodeString Message, bool Fatal);
   void __fastcall SCPSink(const UnicodeString TargetDir,
     const UnicodeString FileName, const UnicodeString SourceDir,

+ 1 - 1
source/core/SftpFileSystem.cpp

@@ -2523,7 +2523,7 @@ unsigned long __fastcall TSFTPFileSystem::GotStatusPacket(
       Error += L"\n\n" + LoadStr(SFTP_STATUS_4);
     }
     FTerminal->TerminalError(NULL, Error, HelpKeyword);
-    return 0;
+    UNREACHABLE_AFTER_NORETURN(return 0);
   }
   else
   {

+ 5 - 5
source/core/Terminal.cpp

@@ -329,7 +329,7 @@ public:
   inline __fastcall TCallbackGuard(TTerminal * FTerminal);
   inline __fastcall ~TCallbackGuard();
 
-  void __fastcall FatalError(Exception * E, const UnicodeString & Msg, const UnicodeString & HelpKeyword);
+  NORETURN void __fastcall FatalError(Exception * E, const UnicodeString & Msg, const UnicodeString & HelpKeyword);
   inline void __fastcall Verify();
   inline bool __fastcall Verify(Exception * E);
   void __fastcall Dismiss();
@@ -362,7 +362,7 @@ __fastcall TCallbackGuard::~TCallbackGuard()
   delete FFatalError;
 }
 //---------------------------------------------------------------------------
-void __fastcall TCallbackGuard::FatalError(Exception * E, const UnicodeString & Msg, const UnicodeString & HelpKeyword)
+NORETURN void __fastcall TCallbackGuard::FatalError(Exception * E, const UnicodeString & Msg, const UnicodeString & HelpKeyword)
 {
   DebugAssert(FGuarding);
 
@@ -2347,12 +2347,12 @@ void __fastcall TTerminal::ReactOnCommand(int /*TFSCommand*/ Cmd)
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall TTerminal::TerminalError(UnicodeString Msg)
+NORETURN void __fastcall TTerminal::TerminalError(UnicodeString Msg)
 {
   TerminalError(NULL, Msg);
 }
 //---------------------------------------------------------------------------
-void __fastcall TTerminal::TerminalError(
+NORETURN void __fastcall TTerminal::TerminalError(
   Exception * E, UnicodeString Msg, UnicodeString HelpKeyword)
 {
   throw ETerminal(E, Msg, HelpKeyword);
@@ -6620,7 +6620,7 @@ TQueueItem * TTerminal::SynchronizeToQueue(
       default:
         DebugFail();
         NotImplemented();
-        break;
+        UNREACHABLE_AFTER_NORETURN(break);
     }
   }
   return Result;

+ 2 - 2
source/core/Terminal.h

@@ -587,8 +587,8 @@ public:
   void __fastcall ChangeFilesProperties(TStrings * FileList,
     const TRemoteProperties * Properties);
   bool __fastcall LoadFilesProperties(TStrings * FileList);
-  void __fastcall TerminalError(UnicodeString Msg);
-  void __fastcall TerminalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
+  NORETURN void __fastcall TerminalError(UnicodeString Msg);
+  NORETURN void __fastcall TerminalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
   void __fastcall ReloadDirectory();
   void __fastcall RefreshDirectory();
   void __fastcall RenameFile(const TRemoteFile * File, const UnicodeString & NewName);

+ 1 - 0
source/putty/defs.h

@@ -255,6 +255,7 @@ struct unicode_data;
     TYPECHECK(object == &((type *)0)->field,                            \
               ((type *)(((char *)(object)) - offsetof(type, field))))
 
+#undef NORETURN // WINSCP
 #if defined __GNUC__ || defined __clang__
 #define NORETURN __attribute__((__noreturn__))
 #elif defined _MSC_VER

+ 1 - 1
source/putty/putty.h

@@ -1808,7 +1808,7 @@ static inline void win_unthrottle(TermWin *win, size_t size)
 /*
  * Global functions not specific to a connection instance.
  */
-void nonfatal(const char *, ...) PRINTF_LIKE(1, 2);
+NORETURN void nonfatal(const char *, ...) PRINTF_LIKE(1, 2); // WINSCP
 NORETURN void modalfatalbox(const char *, ...) PRINTF_LIKE(1, 2);
 NORETURN void cleanup_exit(int);