From ae0b3149badf369eb2b1f10aba830eef8b4af9b4 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 23 Feb 2017 16:49:49 -0500
Subject: [PATCH] DRTVWR-418: Fix a round of compile errors surfaced by
 -std=c++11.

These are mostly things that were in fact erroneous, but accepted by older
compilers.

This changeset has not yet been built with Visual Studio 2013 or Linux gcc,
even with -std=c++11.

This changeset has not been built *without* -std=c++11. It should be used in
conjunction with a corresponding change to LL_BUILD_DARWIN_BASE_SWITCHES in
viewer-build-variables/variables.

This is a work in progress. We do not assert that this changeset completes the
work needed to turn on -std=c++11, even on the Mac.
---
 indra/llcommon/lleventdispatcher.h            |  4 ++--
 indra/llcommon/llpreprocessor.h               | 10 +++-------
 indra/llcommon/tests/llsdserialize_test.cpp   |  2 +-
 indra/llimage/llimagetga.cpp                  |  2 +-
 indra/llmath/v4color.cpp                      |  2 +-
 indra/llmath/v4color.h                        |  2 +-
 indra/llmath/v4coloru.h                       |  2 +-
 indra/llwindow/llopenglview-objc.mm           | 20 +++++++++----------
 indra/llwindow/llwindowmacosx.cpp             |  4 ++--
 indra/newview/llappdelegate-objc.mm           |  2 +-
 indra/newview/llappviewermacosx.cpp           |  3 ++-
 indra/newview/llpanelexperiencelisteditor.cpp |  9 ++++++++-
 indra/newview/llpresetsmanager.cpp            |  3 +--
 indra/newview/llviewerstats.cpp               |  3 ++-
 14 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/indra/llcommon/lleventdispatcher.h b/indra/llcommon/lleventdispatcher.h
index 7acc61de4ec..9e1244ef5bf 100644
--- a/indra/llcommon/lleventdispatcher.h
+++ b/indra/llcommon/lleventdispatcher.h
@@ -47,13 +47,13 @@
 // namespace) that a global 'nil' macro breaks badly.
 #if defined(nil)
 // Capture the value of the macro 'nil', hoping int is an appropriate type.
-static const int nil_(nil);
+static const auto nil_(nil);
 // Now forget the macro.
 #undef nil
 // Finally, reintroduce 'nil' as a properly-scoped alias for the previously-
 // defined const 'nil_'. Make it static since otherwise it produces duplicate-
 // symbol link errors later.
-static const int& nil(nil_);
+static const auto& nil(nil_);
 #endif
 
 #include <string>
diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h
index 3698d9db442..2879038c365 100644
--- a/indra/llcommon/llpreprocessor.h
+++ b/indra/llcommon/llpreprocessor.h
@@ -192,13 +192,9 @@
 # define LL_COMMON_API
 #endif // LL_COMMON_LINK_SHARED
 
-#if LL_WINDOWS
-#define LL_TYPEOF(exp) decltype(exp)
-#elif LL_LINUX
-#define LL_TYPEOF(exp) typeof(exp)
-#elif LL_DARWIN
-#define LL_TYPEOF(exp) typeof(exp)
-#endif
+// With C++11, decltype() is standard. We no longer need a platform-dependent
+// macro to get the type of an expression.
+#define LL_TYPEOF(expr) decltype(expr)
 
 #define LL_TO_STRING_HELPER(x) #x
 #define LL_TO_STRING(x) LL_TO_STRING_HELPER(x)
diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp
index 81b930e1e2c..8836230640a 100644
--- a/indra/llcommon/tests/llsdserialize_test.cpp
+++ b/indra/llcommon/tests/llsdserialize_test.cpp
@@ -1553,7 +1553,7 @@ namespace tut
             params.executable = PYTHON;
             params.args.add(scriptfile.getName());
             LLProcessPtr py(LLProcess::create(params));
-            ensure(STRINGIZE("Couldn't launch " << desc << " script"), py);
+            ensure(STRINGIZE("Couldn't launch " << desc << " script"), bool(py));
             // Implementing timeout would mean messing with alarm() and
             // catching SIGALRM... later maybe...
             int status(0);
diff --git a/indra/llimage/llimagetga.cpp b/indra/llimage/llimagetga.cpp
index 5ad7658ec1b..7c75aa1e2a7 100644
--- a/indra/llimage/llimagetga.cpp
+++ b/indra/llimage/llimagetga.cpp
@@ -811,7 +811,7 @@ bool LLImageTGA::decodeTruecolorRle32( LLImageRaw* raw_image, bool &alpha_opaque
 			}
 
 			src += 4;
-			register U32 value = rgba;
+			U32 value = rgba;
 			do
 			{
 				*dst_pixels = value;
diff --git a/indra/llmath/v4color.cpp b/indra/llmath/v4color.cpp
index 79a64b24f2c..a8768bda35e 100644
--- a/indra/llmath/v4color.cpp
+++ b/indra/llmath/v4color.cpp
@@ -122,7 +122,7 @@ LLColor4 LLColor4::cyan6(0.2f, 0.6f, 0.6f, 1.0f);
 //////////////////////////////////////////////////////////////////////////////
 
 // conversion
-LLColor4::operator const LLColor4U() const
+LLColor4::operator LLColor4U() const
 {
 	return LLColor4U(
 		(U8)llclampb(ll_round(mV[VRED]*255.f)),
diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h
index 0d632f59be3..8f353ead5a2 100644
--- a/indra/llmath/v4color.h
+++ b/indra/llmath/v4color.h
@@ -131,7 +131,7 @@ class LLColor4
 		friend const LLColor4& operator*=(LLColor4 &a, const LLColor4 &b); // Doesn't multiply alpha! (for lighting)
 
 		// conversion
-		operator const LLColor4U() const;
+		operator LLColor4U() const;
 
 		// Basic color values.
 		static LLColor4 red;
diff --git a/indra/llmath/v4coloru.h b/indra/llmath/v4coloru.h
index 704ce852d92..0f2eff3d143 100644
--- a/indra/llmath/v4coloru.h
+++ b/indra/llmath/v4coloru.h
@@ -120,7 +120,7 @@ class LLColor4U
 	static BOOL parseColor4U(const std::string& buf, LLColor4U* value);
 
 	// conversion
-	operator const LLColor4() const
+	operator LLColor4() const
 	{
 		return LLColor4(*this);
 	}
diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm
index 22f3339cf19..c8c086d705c 100644
--- a/indra/llwindow/llopenglview-objc.mm
+++ b/indra/llwindow/llopenglview-objc.mm
@@ -232,8 +232,8 @@ attributedStringInfo getSegments(NSAttributedString *str)
 		NSOpenGLPFADoubleBuffer,
 		NSOpenGLPFAClosestPolicy,
 		NSOpenGLPFAAccelerated,
-		NSOpenGLPFASampleBuffers, (samples > 0 ? 1 : 0),
-		NSOpenGLPFASamples, samples,
+		NSOpenGLPFASampleBuffers, static_cast<NSOpenGLPixelFormatAttribute>(samples > 0 ? 1 : 0),
+		NSOpenGLPFASamples, static_cast<NSOpenGLPixelFormatAttribute>(samples),
 		NSOpenGLPFAStencilSize, 8,
 		NSOpenGLPFADepthSize, 24,
 		NSOpenGLPFAAlphaSize, 8,
@@ -370,8 +370,8 @@ attributedStringInfo getSegments(NSAttributedString *str)
 - (void)mouseMoved:(NSEvent *)theEvent
 {
 	float mouseDeltas[2] = {
-		[theEvent deltaX],
-		[theEvent deltaY]
+		float([theEvent deltaX]),
+		float([theEvent deltaY])
 	};
 	
 	callDeltaUpdate(mouseDeltas, 0);
@@ -391,8 +391,8 @@ attributedStringInfo getSegments(NSAttributedString *str)
 	// The old CoreGraphics APIs we previously relied on are now flagged as obsolete.
 	// NSEvent isn't obsolete, and provides us with the correct deltas.
 	float mouseDeltas[2] = {
-		[theEvent deltaX],
-		[theEvent deltaY]
+		float([theEvent deltaX]),
+		float([theEvent deltaY])
 	};
 	
 	callDeltaUpdate(mouseDeltas, 0);
@@ -592,13 +592,13 @@ attributedStringInfo getSegments(NSAttributedString *str)
     if (mMarkedTextAllowed)
     {
         unsigned int selected[2] = {
-            selectedRange.location,
-            selectedRange.length
+            unsigned(selectedRange.location),
+            unsigned(selectedRange.length)
         };
         
         unsigned int replacement[2] = {
-            replacementRange.location,
-            replacementRange.length
+            unsigned(replacementRange.location),
+            unsigned(replacementRange.length)
         };
         
         int string_length = [aString length];
diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index 754306b5d25..5fa55d0b1f6 100644
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -544,7 +544,7 @@ void getPreeditLocation(float *location, unsigned int length)
 		
 		preeditor->getPreeditLocation(length, &coord, &rect, NULL);
 		
-		float c[4] = {coord.mX, coord.mY, 0, 0};
+		float c[4] = {float(coord.mX), float(coord.mY), 0, 0};
 		
 		convertRectToScreen(gWindowImplementation->getWindow(), c);
 		
@@ -899,7 +899,7 @@ BOOL LLWindowMacOSX::setPosition(const LLCoordScreen position)
 {
 	if(mWindow)
 	{
-		float pos[2] = {position.mX, position.mY};
+		float pos[2] = {float(position.mX), float(position.mY)};
 		setWindowPos(mWindow, pos);
 	}
 
diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm
index 8188c6c3f99..aebae4c4344 100644
--- a/indra/newview/llappdelegate-objc.mm
+++ b/indra/newview/llappdelegate-objc.mm
@@ -97,7 +97,7 @@
 	callWindowUnhide();
 }
 
-- (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender
+- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender
 {
 	// run one frame to assess state
 	if (!pumpMainLoop())
diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp
index bb3bcf2886e..d472f8926b1 100644
--- a/indra/newview/llappviewermacosx.cpp
+++ b/indra/newview/llappviewermacosx.cpp
@@ -302,7 +302,8 @@ void LLAppViewerMacOSX::initCrashReporting(bool reportFreeze)
     std::string appname = gDirUtilp->getExecutableFilename();
     std::string str[] = { "-pid", pid_str.str(), "-dumpdir", logdir, "-procname", appname.c_str() };
     std::vector< std::string > args( str, str + ( sizeof ( str ) /  sizeof ( std::string ) ) );
-    LL_WARNS() << "about to launch mac-crash-logger" << pid_str << " " << logdir << " " << appname << LL_ENDL;
+    LL_WARNS() << "about to launch mac-crash-logger" << pid_str.str()
+               << " " << logdir << " " << appname << LL_ENDL;
     launchApplication(&command_str, &args);
 }
 
diff --git a/indra/newview/llpanelexperiencelisteditor.cpp b/indra/newview/llpanelexperiencelisteditor.cpp
index 32ec4930ab8..0fdb9a57f3e 100644
--- a/indra/newview/llpanelexperiencelisteditor.cpp
+++ b/indra/newview/llpanelexperiencelisteditor.cpp
@@ -39,6 +39,8 @@
 #include "llagent.h"
 #include "lltextbox.h"
 #include "lltrans.h"
+#include "llsdutil.h"
+#include <boost/foreach.hpp>
 
 
 static LLPanelInjector<LLPanelExperienceListEditor> t_panel_experience_list_editor("panel_experience_list_editor");
@@ -94,7 +96,12 @@ void LLPanelExperienceListEditor::addExperienceIds( const uuid_vec_t& experience
 void LLPanelExperienceListEditor::setExperienceIds( const LLSD& experience_ids )
 {
 	mExperienceIds.clear();
-	mExperienceIds.insert(experience_ids.beginArray(), experience_ids.endArray());
+	BOOST_FOREACH(LLSD uuid, llsd::inArray(experience_ids))
+	{
+		// Using insert(range) doesn't work here because the conversion from
+		// LLSD to LLUUID is ambiguous: have to specify asUUID() for each entry.
+		mExperienceIds.insert(uuid.asUUID());
+	}
 	onItems();
 }
 
diff --git a/indra/newview/llpresetsmanager.cpp b/indra/newview/llpresetsmanager.cpp
index f40b3e02952..214d221716e 100644
--- a/indra/newview/llpresetsmanager.cpp
+++ b/indra/newview/llpresetsmanager.cpp
@@ -165,8 +165,7 @@ bool LLPresetsManager::savePreset(const std::string& subdirectory, std::string n
 	}
     else if(PRESETS_CAMERA == subdirectory)
 	{
-		name_list = boost::assign::list_of
-			("Placeholder");
+		name_list = {"Placeholder"};
 	}
     else
     {
diff --git a/indra/newview/llviewerstats.cpp b/indra/newview/llviewerstats.cpp
index f52c82dab7d..e918c7352cf 100644
--- a/indra/newview/llviewerstats.cpp
+++ b/indra/newview/llviewerstats.cpp
@@ -307,7 +307,8 @@ U32Bytes				gTotalWorldData,
 U32								gSimPingCount = 0;
 U32Bits				gObjectData;
 F32Milliseconds		gAvgSimPing(0.f);
-U32Bytes			gTotalTextureBytesPerBoostLevel[LLViewerTexture::MAX_GL_IMAGE_CATEGORY] = {U32Bytes(0)};
+// rely on default initialization
+U32Bytes			gTotalTextureBytesPerBoostLevel[LLViewerTexture::MAX_GL_IMAGE_CATEGORY];
 
 extern U32  gVisCompared;
 extern U32  gVisTested;
-- 
GitLab