diff --git a/Common/GamePad.cpp b/Common/GamePad.cpp
index dc5181dfaa1972561d7fa86ec1e7a58947a24073..08c60a9c6fabcbfbacd8cfd785c724b15cbbb2db 100644
--- a/Common/GamePad.cpp
+++ b/Common/GamePad.cpp
@@ -53,6 +53,7 @@
 #include <string>
 #include <iostream>
 #include <stdio.h>
+#include <algorithm>
 #include "GamePad.h"
 
 #if !defined(WIN32)
diff --git a/Fltk/Navigator.cpp b/Fltk/Navigator.cpp
index e08ba92c20b7a261f950dba2c3fb72b15a116e57..0cc4d4fd3f9394774f08df9a21cc049f5cfa7795 100644
--- a/Fltk/Navigator.cpp
+++ b/Fltk/Navigator.cpp
@@ -8,7 +8,8 @@
 #include <string>
 #include <iostream>
 #include <stdio.h>
-#include <Navigator.h>
+#include <algorithm>
+#include "Navigator.h"
 #include "Trackball.h"
 #include "Context.h"
 #include "drawContext.h"
diff --git a/Fltk/clippingWindow.cpp b/Fltk/clippingWindow.cpp
index da504cc56a2cdc0c9ce0a7c66bde095269a594e3..0a0d262cf9bef116eb3b11fff899561703aba14d 100644
--- a/Fltk/clippingWindow.cpp
+++ b/Fltk/clippingWindow.cpp
@@ -5,6 +5,7 @@
 
 #include <FL/Fl_Tabs.H>
 #include <FL/Fl_Return_Button.H>
+#include <algorithm>
 #include "FlGui.h"
 #include "drawContext.h"
 #include "clippingWindow.h"
diff --git a/Fltk/drawContextFltkStringTexture.cpp b/Fltk/drawContextFltkStringTexture.cpp
index 6c20e0622c98ec3502bdc56d27a50ccc71c333a9..a20a010285c31c07672d33cbe7c56846f857f17b 100644
--- a/Fltk/drawContextFltkStringTexture.cpp
+++ b/Fltk/drawContextFltkStringTexture.cpp
@@ -6,6 +6,7 @@
 // Contributed by Jonathan Lambrechts
 
 #include "drawContextFltkStringTexture.h"
+#include <algorithm>
 
 // FIXME: hack for current version of mingw
 #if defined(WIN32) && !defined(GL_TEXTURE_RECTANGLE_ARB)
diff --git a/Fltk/gamepadWindow.cpp b/Fltk/gamepadWindow.cpp
index 5393dbda4874d4efd1489f56599001c5bc643af3..ad04765279b8f7a339965c8542e9c95dc7e4c952 100644
--- a/Fltk/gamepadWindow.cpp
+++ b/Fltk/gamepadWindow.cpp
@@ -11,6 +11,7 @@ typedef unsigned long intptr_t;
 #endif
 #include <string.h>
 #include <FL/Fl.H>
+#include <algorithm>
 #include "FlGui.h"
 #include "paletteWindow.h"
 #include "optionWindow.h"
@@ -50,7 +51,7 @@ gamepadWindow::gamepadWindow()
   int width = 34 * FL_NORMAL_SIZE + WB;
   int height = 15 * BH + 4 * WB;
   int L =  FL_NORMAL_SIZE;
- 
+
   win = new paletteWindow
     (width, height, CTX::instance()->nonModalWindows ? true : false);
   win->box(GMSH_WINDOW_BOX);
diff --git a/Geo/MEdge.cpp b/Geo/MEdge.cpp
index 3f7112606c88f738540af46ecd2a96c93f26fa2d..45303485ada2143adbe76b3963f11c9c808b019e 100644
--- a/Geo/MEdge.cpp
+++ b/Geo/MEdge.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "MEdge.h"
 #include "Numeric.h"
 
diff --git a/Geo/OCC_Connect.cpp b/Geo/OCC_Connect.cpp
index ff3700017ca8b9e5212779b68d4faee490138a43..20b4381190d38a2ec300e3f66a5e3e0973d9791a 100644
--- a/Geo/OCC_Connect.cpp
+++ b/Geo/OCC_Connect.cpp
@@ -6,12 +6,12 @@
 // Contributed by Mark van Doesburg, Technolution B.V.
 
 #include "OCC_Connect.h"
-
 #include <vector>
 #include <list>
 #include <deque>
 #include <iostream>
 #include <iterator>
+#include <algorithm>
 
 #if defined(HAVE_OCC)
 
diff --git a/Geo/STensor3.cpp b/Geo/STensor3.cpp
index fc5571630baa3d21e300f64d5481aeebd3cc74cf..bb6af299161e985e83cdfabbefa3cc595a6cf0d2 100644
--- a/Geo/STensor3.cpp
+++ b/Geo/STensor3.cpp
@@ -3,9 +3,11 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
-// compute the largest inscribed ellipsoid...
+#include <algorithm>
 #include "STensor3.h"
 
+// compute the largest inscribed ellipsoid
+
 void SMetric3::print (const char *s) const
 {
   printf(" metric %s : %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E \n", s,
@@ -38,7 +40,8 @@ SMetric3 intersection (const SMetric3 &m1, const SMetric3 &m2)
 
   // Correction from the PhD thesis of Frederic Alauzet p.16
   // If m2 = alpha*m1, then take the largest metric
-  static const double eps = 1.e-2;                              // Tolerance to detect triple eigenvalue (i.e. proportional metrics)
+  static const double eps = 1.e-2;  // Tolerance to detect triple eigenvalue
+                                    // (i.e. proportional metrics)
   const double max_eig = std::max(S(0), std::max(S(1), S(2)));
   const double min_eig = std::min(S(0), std::min(S(1), S(2)));
   const double range_eig = fabs((max_eig-min_eig)/max_eig);
diff --git a/Graphics/Camera.cpp b/Graphics/Camera.cpp
index 74c47fdf7c3c55ba52660ada37a084dd5ec9fc59..9a8426e0f1b396de9441c1707445e82c94a9fe4b 100644
--- a/Graphics/Camera.cpp
+++ b/Graphics/Camera.cpp
@@ -9,6 +9,7 @@
 #include <iostream>
 #include <stdio.h>
 #include <math.h>
+#include <algorithm>
 #include "Camera.h"
 #include "Gmsh.h"
 #include "GmshConfig.h"
@@ -34,7 +35,7 @@ void Camera::init()
   glFnear=.0001*distance;
   glFfar=10000*distance;
   this->update();
-   
+
 }
 
 void Camera::alongX()
@@ -152,11 +153,11 @@ void Camera::update()
   right.x = front.y * up.z - front.z * up.y;
   right.y = front.z * up.x - front.x * up.z;
   right.z = front.x * up.y - front.y * up.x;
-    
+
   up.x = right.y * front.z - right.z * front.y;
   up.y = right.z * front.x - right.x * front.z;
   up.z = right.x * front.y - right.y * front.x;
-   
+
   ref_distance = distance;
   normalize(up);
   normalize(right);
@@ -171,23 +172,23 @@ void Camera::update()
   ndfl = glFnear / focallength;
 }
 
-void Camera::affiche() 
+void Camera::affiche()
 {
-  std::cout<<"  ------------ GENERAL PARAMETERS ------------"   <<std::endl ;       
-  std::cout<<"  CTX aperture "<< CTX::instance()->camera_aperture <<std::endl ;    
-  std::cout<<"  CTX eyesep ratio "<< CTX::instance()->eye_sep_ratio <<std::endl ;    
-  std::cout<<"  CTX focallength ratio "<< CTX::instance()->focallength_ratio <<std::endl ;    
-  std::cout<<"  ------------ CAMERA PARAMETERS ------------"   <<std::endl ;         
-  std::cout<<"  position "<<  position.x<<","<<position.y<<","<<position.z <<std::endl ;    
-  std::cout<<"  front "<<  front.x<<","<<front.y<<","<<front.z <<std::endl;              
-  std::cout<<"  up "<< up.x<<","<<up.y<<","<<up.z <<std::endl;                 
-  std::cout<<"  right "<< right.x<<","<<right.y<<","<<right.z  <<std::endl;              
-  std::cout<<"  target "<<  target.x<<","<<target.y<<","<<target.z <<std::endl;   
-  std::cout<<"  focallength_ratio "<<focallength_ratio <<std::endl;  
-  std::cout<<"  focallength "<<focallength <<std::endl;  
-  std::cout<<"  aperture "<<aperture <<std::endl;     
-  std::cout<<"  eyesep_ratio "<<eye_sep_ratio <<std::endl;       
-  std::cout<<"  eyesep "<<eyesep <<std::endl;       
+  std::cout<<"  ------------ GENERAL PARAMETERS ------------"   <<std::endl ;
+  std::cout<<"  CTX aperture "<< CTX::instance()->camera_aperture <<std::endl ;
+  std::cout<<"  CTX eyesep ratio "<< CTX::instance()->eye_sep_ratio <<std::endl ;
+  std::cout<<"  CTX focallength ratio "<< CTX::instance()->focallength_ratio <<std::endl ;
+  std::cout<<"  ------------ CAMERA PARAMETERS ------------"   <<std::endl ;
+  std::cout<<"  position "<<  position.x<<","<<position.y<<","<<position.z <<std::endl ;
+  std::cout<<"  front "<<  front.x<<","<<front.y<<","<<front.z <<std::endl;
+  std::cout<<"  up "<< up.x<<","<<up.y<<","<<up.z <<std::endl;
+  std::cout<<"  right "<< right.x<<","<<right.y<<","<<right.z  <<std::endl;
+  std::cout<<"  target "<<  target.x<<","<<target.y<<","<<target.z <<std::endl;
+  std::cout<<"  focallength_ratio "<<focallength_ratio <<std::endl;
+  std::cout<<"  focallength "<<focallength <<std::endl;
+  std::cout<<"  aperture "<<aperture <<std::endl;
+  std::cout<<"  eyesep_ratio "<<eye_sep_ratio <<std::endl;
+  std::cout<<"  eyesep "<<eyesep <<std::endl;
   std::cout<<"  screenwidth "<<screenwidth <<std::endl;
   std::cout<<"  screenheight "<<screenheight <<std::endl;
   std::cout<<"  distance "<<distance <<std::endl;
@@ -199,7 +200,7 @@ void Camera::affiche()
   std::cout<<"  Lc "<< Lc<<std::endl;
   std::cout<<"  eye_sep_ratio "<<eye_sep_ratio <<std::endl;
   std::cout<<"  closeness "<< closeness<<std::endl;
-  std::cout<<"  glFnear "<< glFnear <<std::endl; 
+  std::cout<<"  glFnear "<< glFnear <<std::endl;
   std::cout<<"  glFfar "<< glFfar <<std::endl;
   std::cout<<"  radians "<<radians <<std::endl;
   std::cout<<"  wd2 "<<wd2 <<std::endl;
@@ -230,21 +231,21 @@ void Camera::zoom(double& factor)
 void Camera::rotate(double* q)
 {
   this->update();
-  // rotation projection in global coordinates  
+  // rotation projection in global coordinates
   Quaternion omega;
   omega.x = q[0] * right.x + q[1] * up.x - q[2] * front.x;
   omega.y = q[0] * right.y + q[1] * up.y - q[2] * front.y;
   omega.z = q[0] * right.z + q[1] * up.z - q[2] * front.z;
   omega.w = q[3];
   normalize(omega);
-  Quaternion conj = conjugate(omega);  
+  Quaternion conj = conjugate(omega);
   front = omega * front * conj;
   up = omega * up * conj;
   right = omega * right * conj;
   normalize(front);
   normalize(up);
   normalize(right);
-  //actualize camera position 
+  //actualize camera position
   position = target - distance * front;
   this->update();
 }
@@ -275,7 +276,7 @@ void Camera::move_and_look(double _movfront,double _movright,double _movup,
   Quaternion omega;
   omega = omega_up * omega_right * omega_front;
   normalize(omega);
-  Quaternion conj = conjugate(omega);  
+  Quaternion conj = conjugate(omega);
   front = omega * front * conj;
   up = omega * up * conj;
   right = omega * right * conj;
@@ -307,10 +308,10 @@ void Camera::move_and_look(double _movfront,double _movright,double _movup,
 ////////////////////////////////////////////////////////////////
 //                 QUATERNION and XYZ functions
 ////////////////////////////////////////////////////////////////
- 
+
 double length(Quaternion &q)
-{ 
-  return  sqrt(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w); 
+{
+  return  sqrt(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
 }
 
 double length(XYZ &p)
@@ -330,14 +331,14 @@ void normalize_axe(Quaternion &q)
     l = 0.;
   }
   if(l != 0. ){
-    q.x /= l; q.y /= l; q.z /= l; 
+    q.x /= l; q.y /= l; q.z /= l;
    }
 }
 void normalize(Quaternion &q)
 {
   double L = length(q);
-    q.x /= L; q.y /= L; q.z /= L; q.w /= L; 
-  
+    q.x /= L; q.y /= L; q.z /= L; q.w /= L;
+
 }
 
 void normalize(XYZ &p)
@@ -346,7 +347,7 @@ void normalize(XYZ &p)
   p.x /= L; p.y /= L; p.z /= L;
 }
 
-XYZ::XYZ (const Quaternion &R) : x(R.x), y(R.y), z(R.z){} 
+XYZ::XYZ (const Quaternion &R) : x(R.x), y(R.y), z(R.z){}
 
 XYZ::XYZ(double _x,double _y,double _z) : x(_x),y(_y),z(_z){}
 
@@ -363,7 +364,7 @@ void rotate(Quaternion omega,XYZ axe)
 }
 
 XYZ operator* (const double &a, const XYZ &T)
-{ 
+{
   XYZ res(T);
   res.x *= a;
   res.y *= a;
@@ -372,7 +373,7 @@ XYZ operator* (const double &a, const XYZ &T)
 }
 
 XYZ operator+ (const XYZ &L, const XYZ &R)
-{ 
+{
   XYZ res(L);
   res.x += R.x;
   res.y += R.y;
@@ -380,7 +381,7 @@ XYZ operator+ (const XYZ &L, const XYZ &R)
   return res;
 }
 XYZ operator- (const XYZ &L, const XYZ &R)
-{ 
+{
   XYZ res(L);
   res.x -= R.x;
   res.y -= R.y;
@@ -388,7 +389,7 @@ XYZ operator- (const XYZ &L, const XYZ &R)
   return res;
 }
 XYZ operator- (const XYZ &R)
-{ 
+{
   XYZ res;
   res.x = -R.x;
   res.y = -R.y;
@@ -402,7 +403,7 @@ Quaternion::Quaternion(const XYZ &R, const double &A) {
   x=R.x*sin(A);
   y=R.y*sin(A);
   z=R.z*sin(A);
-  w=cos(A); 
+  w=cos(A);
 }
 Quaternion::Quaternion(): x(0.), y(0.),z(0.),w(1.) {}
 
diff --git a/Graphics/drawGraph2d.cpp b/Graphics/drawGraph2d.cpp
index 7c5edbe7b38dc62538a05d402314902ccdc44431..0e3966f40823d1d73a193435fbe8e4c4a76149fb 100644
--- a/Graphics/drawGraph2d.cpp
+++ b/Graphics/drawGraph2d.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "drawContext.h"
 #include "PView.h"
 #include "PViewOptions.h"
diff --git a/Graphics/drawScales.cpp b/Graphics/drawScales.cpp
index ef9a304c4fa30c9117a5e86176c58e0ceaa4ffbd..7d61de1a280674c73729b5449464e24d7561eaf1 100644
--- a/Graphics/drawScales.cpp
+++ b/Graphics/drawScales.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "drawContext.h"
 #include "PView.h"
 #include "PViewOptions.h"
diff --git a/Numeric/ConjugateGradients.cpp b/Numeric/ConjugateGradients.cpp
index 666267c31e9696693be81f02fe3883654d4a8013..7a4d9af0dc91149944ef0607cadbb873422d0cee 100644
--- a/Numeric/ConjugateGradients.cpp
+++ b/Numeric/ConjugateGradients.cpp
@@ -1,3 +1,9 @@
+// Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to the public mailing list <gmsh@geuz.org>.
+
+#include <algorithm>
 #include <math.h>
 #include "GmshMessage.h"
 #include "ConjugateGradients.h"
@@ -15,16 +21,16 @@ static void scale (std::vector<double> &x, double s){
   for (unsigned int i=0;i<x.size();i++)x[i]*=s;
 }
 
-static void gmshLineSearch(void (*func)(std::vector<double> &x, 
+static void gmshLineSearch(void (*func)(std::vector<double> &x,
 					double &Obj,
 					bool needGrad,
 					std::vector<double> &gradObj, void *), // the function
 			   void* data, // eventual data
-			   std::vector<double> &x, // variables 
+			   std::vector<double> &x, // variables
 			   std::vector<double> &p, // search direction
 			   std::vector<double> &g, // gradient
 			   double &f,
-			   double stpmax, 
+			   double stpmax,
 			   int &check)
 {
   int i;
@@ -99,7 +105,7 @@ static void gmshLineSearch(void (*func)(std::vector<double> &x,
 
 // Simple Gradient Descent Minimization (use finite differences to compute the gradient)
 
-double GradientDescent(void (*func)(std::vector<double> &x, 
+double GradientDescent(void (*func)(std::vector<double> &x,
 				    double &Obj,
 				    bool needGrad,
 				    std::vector<double> &gradObj, void *), // its gradient
diff --git a/Numeric/ConjugateGradients.h b/Numeric/ConjugateGradients.h
index 65cac55754636bf5d58efccd5eb86b75e0c412e5..0444f925397f6f701ec1c89f9719deafc32ff26b 100644
--- a/Numeric/ConjugateGradients.h
+++ b/Numeric/ConjugateGradients.h
@@ -1,9 +1,14 @@
+// Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to the public mailing list <gmsh@geuz.org>.
+
 #ifndef  _CONJUGATEGRADIENTS
 #define  _CONJUGATEGRADIENTS
 
 #include <vector>
 
-double GradientDescent(void (*func)(std::vector<double> &x, 
+double GradientDescent(void (*func)(std::vector<double> &x,
 				    double &Obj,
 				    bool needGrad,
 				    std::vector<double> &gradObj, void *),
diff --git a/Numeric/Numeric.cpp b/Numeric/Numeric.cpp
index e38ab1b70ec4e8d81a9a5ea7c105924810be3b86..a30e3f6df1a01f90bc394a8e1c3315bfc981911b 100644
--- a/Numeric/Numeric.cpp
+++ b/Numeric/Numeric.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "GmshConfig.h"
 #include "GmshMessage.h"
 #include "Numeric.h"
@@ -1373,7 +1374,7 @@ int intersection_segments(const SPoint3 &p1, const SPoint3 &p2,
       return false;
     }
     return true;
-  }  
+  }
   return false;
 }
 
diff --git a/Numeric/bezierBasis.cpp b/Numeric/bezierBasis.cpp
index 78df24305de04c5eb625e9a7fb17263bba8215d4..c48eb997851b1c2b674ad4d3f6ccf3e3c4ab7be8 100644
--- a/Numeric/bezierBasis.cpp
+++ b/Numeric/bezierBasis.cpp
@@ -3,7 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
-
+#include <algorithm>
 #include "GmshDefines.h"
 #include "GmshMessage.h"
 #include <vector>
@@ -12,8 +12,6 @@
 #include "pointsGenerators.h"
 #include "BasisFactory.h"
 #include "Numeric.h"
-#include <sstream>
-
 
 namespace {
 // Sub Control Points
diff --git a/Numeric/decasteljau.cpp b/Numeric/decasteljau.cpp
index 74cd8723c90974b095524a5c66040d520dc84f86..24dabffb0b8fad47346fe20e2e49aaed201ef15d 100644
--- a/Numeric/decasteljau.cpp
+++ b/Numeric/decasteljau.cpp
@@ -5,6 +5,7 @@
 //
 // Contributed by J. Lambrechts
 
+#include <algorithm>
 #include "decasteljau.h"
 #include "SPoint3.h"
 #include "SVector3.h"
diff --git a/Numeric/discreteFrechetDistance.cpp b/Numeric/discreteFrechetDistance.cpp
index 94f4cadf05eb3789a398552d49a582cec76eef21..b7b5c4a591b14cd95c1bb8b196331188162045ab 100644
--- a/Numeric/discreteFrechetDistance.cpp
+++ b/Numeric/discreteFrechetDistance.cpp
@@ -3,10 +3,12 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "discreteFrechetDistance.h"
 #include "fullMatrix.h"
 
-static double distance (const SPoint3 &p1, const SPoint3 &p2){
+static double distance (const SPoint3 &p1, const SPoint3 &p2)
+{
   return p1.distance(p2);
 }
 
diff --git a/Numeric/fullMatrix.cpp b/Numeric/fullMatrix.cpp
index a7544b5ef1f2878fec11088ed8acec1324f31c30..cd3187eb76f3c31ec80a1be9af6a2e55a3b63bcc 100644
--- a/Numeric/fullMatrix.cpp
+++ b/Numeric/fullMatrix.cpp
@@ -5,6 +5,7 @@
 
 #include <complex>
 #include <string.h>
+#include <algorithm>
 #include "GmshConfig.h"
 #include "fullMatrix.h"
 #include "GmshMessage.h"
diff --git a/Numeric/jacobiPolynomials.cpp b/Numeric/jacobiPolynomials.cpp
index 0f473a84c904dcf6455babd3dae485cb2ee0d548..e9d955ac8552aa8f318960503dd4042460b4daff 100644
--- a/Numeric/jacobiPolynomials.cpp
+++ b/Numeric/jacobiPolynomials.cpp
@@ -3,11 +3,10 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
-#include "jacobiPolynomials.h"
+#include <algorithm>
 #include <cmath>
 #include <iostream>
-
-
+#include "jacobiPolynomials.h"
 
 inline double Pochhammer(double x,int n)
 {
@@ -16,17 +15,11 @@ inline double Pochhammer(double x,int n)
   return result;
 }
 
-
-
 JacobiPolynomials::JacobiPolynomials(double a, double b, int o):
   alpha(a),beta(b),n(o),alphaPlusBeta(a+b),a2MinusB2(a*a-b*b) {}
 
-
-
 JacobiPolynomials::~JacobiPolynomials() {;}
 
-
-
 void JacobiPolynomials::f(double u, double *val) const
 {
   val[0] = 1.;
@@ -43,15 +36,11 @@ void JacobiPolynomials::f(double u, double *val) const
     double a4i = 2.*(ii+alpha)*(ii+beta)*(twoI+alphaPlusBeta+2.);
 
     val[i+1] = ((a2i + a3i * u)* val[i] - a4i * val[i-1])/a1i;
-
   }
 }
 
-
-
 void JacobiPolynomials::df(double u, double *val) const
 {
-
   // Indeterminate form for u == -1 and u == 1
   // TODO: Extend to non-integer alpha & beta?
   if ((u == 1.) || (u == -1.)) {
@@ -71,7 +60,6 @@ void JacobiPolynomials::df(double u, double *val) const
     if ((u == -1.) && (n >= 2)) for (int k=2;k<=n;k+=2) val[k] = -val[k];
 
     return;
-
   }
 
   // Now general case
diff --git a/Numeric/nodalBasis.cpp b/Numeric/nodalBasis.cpp
index a443c6187ba41b9b0aeb1e9e59e39f62911800e8..683a976aef096d06ef7cae5a04aa4ce8994786d1 100644
--- a/Numeric/nodalBasis.cpp
+++ b/Numeric/nodalBasis.cpp
@@ -5,12 +5,11 @@
 
 #include <limits>
 #include <cmath>
+#include <algorithm>
 #include "nodalBasis.h"
 #include "BasisFactory.h"
 #include "pointsGenerators.h"
 
-
-
 namespace ClosureGen {
   inline double pow2(double x)
   {
@@ -40,7 +39,8 @@ namespace ClosureGen {
     }
   }
 
-  void rotateHexFull(int iFace, int iRot, int iSign, double uI, double vI, double wI, double &uO, double &vO, double &wO)
+  void rotateHexFull(int iFace, int iRot, int iSign, double uI, double vI,
+                     double wI, double &uO, double &vO, double &wO)
   {
     switch (iFace) {
       case 0: uO = uI; vO = vI; wO = wI; break;
@@ -344,7 +344,8 @@ namespace ClosureGen {
                               bool serendip, const fullMatrix<double> &points)
   {
     closure.clear();
-    const nodalBasis &fsFace = *BasisFactory::getNodalBasis(ElementType::getTag(TYPE_QUA, order, serendip));
+    const nodalBasis &fsFace = *BasisFactory::getNodalBasis
+      (ElementType::getTag(TYPE_QUA, order, serendip));
     for (int iRotate = 0; iRotate < 4; iRotate++){
       for (int iSign = 1; iSign >= -1; iSign -= 2){
         for (int iFace = 0; iFace < 6; iFace++) {
@@ -648,7 +649,8 @@ nodalBasis::nodalBasis(int tag)
 
 }
 
-void nodalBasis::getReferenceNodesForBezier(fullMatrix<double> &nodes) const {
+void nodalBasis::getReferenceNodesForBezier(fullMatrix<double> &nodes) const
+{
   if (parentType != TYPE_PYR && !serendip) {
     nodes = points;
   }
diff --git a/Numeric/pyramidalBasis.cpp b/Numeric/pyramidalBasis.cpp
index aa9c8b2c932564569f905711c2289605ce71a71f..6260e06694199d38863e97c90300d482a8fbae1b 100644
--- a/Numeric/pyramidalBasis.cpp
+++ b/Numeric/pyramidalBasis.cpp
@@ -3,9 +3,10 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <cmath>
+#include <algorithm>
 #include "pyramidalBasis.h"
 #include "pointsGenerators.h"
-#include <cmath>
 
 pyramidalBasis::pyramidalBasis(int tag) : nodalBasis(tag)
 {
@@ -39,7 +40,7 @@ pyramidalBasis::pyramidalBasis(int tag) : nodalBasis(tag)
         monomials(idx,0) = i;
         monomials(idx,1) = j;
         monomials(idx,2) = k;
-        
+
         for (int l=0;l<num_points;l++) {
           double oneMinW = std::max(1e-14,1-points(l,2));
           VDM(idx,l)  = std::pow(points(l,0),i);
diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp
index 048fe191751a86d651805246870c46b19d0a0dda..55a9eca6a50bd0b6f0f87f6fe49acc61243f73b3 100644
--- a/Parser/Gmsh.tab.cpp
+++ b/Parser/Gmsh.tab.cpp
@@ -11723,7 +11723,7 @@ void yymsg(int level, const char *fmt, ...)
     Msg::Error("'%s', line %d : %s", gmsh_yyname.c_str(), gmsh_yylineno - 1, tmp);
     gmsh_yyerrorstate++;
   }
-  else
+  else{
     Msg::Warning("'%s', line %d : %s", gmsh_yyname.c_str(), gmsh_yylineno - 1, tmp);
-
+  }
 }
diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y
index c71ea22791e5295d14c37639a4b4a4eee98500b9..3e83da6e53e012842ca9bbdfbc3f42022ea97445 100644
--- a/Parser/Gmsh.y
+++ b/Parser/Gmsh.y
@@ -642,7 +642,7 @@ NumericIncrement :
   | tMINUSMINUS    { $$ = -1; }
 ;
 
-// these are for either compatibility with getdp syntax (square brackets instead
+// these are for compatibility with the syntax in GetDP (square brackets instead
 // of parentheses)
 
 LP : '(' { $$ = (char*)"("; } | '[' { $$ = (char*)"["; } ;
@@ -5576,7 +5576,7 @@ void yymsg(int level, const char *fmt, ...)
     Msg::Error("'%s', line %d : %s", gmsh_yyname.c_str(), gmsh_yylineno - 1, tmp);
     gmsh_yyerrorstate++;
   }
-  else
+  else{
     Msg::Warning("'%s', line %d : %s", gmsh_yyname.c_str(), gmsh_yylineno - 1, tmp);
-
+  }
 }
diff --git a/Plugin/LongitudeLatitude.cpp b/Plugin/LongitudeLatitude.cpp
index a4864c9277de66de5f84d4fc842f3e59bb185f9b..44eaf4b2b00a6b7622d86805397f7cf01ad46e10 100644
--- a/Plugin/LongitudeLatitude.cpp
+++ b/Plugin/LongitudeLatitude.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "LongitudeLatitude.h"
 #include "OpenFile.h"
 
diff --git a/Plugin/ModifyComponent.cpp b/Plugin/ModifyComponent.cpp
index 3802181a3a9aa2566559c7c8e581e6de23395de1..0bdb985361803c0ba1cae941e2a5a3232a776b80 100644
--- a/Plugin/ModifyComponent.cpp
+++ b/Plugin/ModifyComponent.cpp
@@ -4,6 +4,7 @@
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
 #include <vector>
+#include <algorithm>
 #include "GmshConfig.h"
 #include "ModifyComponent.h"
 #include "OctreePost.h"
diff --git a/Post/ColorTable.cpp b/Post/ColorTable.cpp
index 63b018b6d3b963b5efbe2ec0ef2b4733b911d156..8ddfbd9d132c4b0358caa195c53b53fb5f90098a 100644
--- a/Post/ColorTable.cpp
+++ b/Post/ColorTable.cpp
@@ -13,6 +13,7 @@
 // and Andre Battaiola.
 
 #include <string.h>
+#include <algorithm>
 #include "GmshMessage.h"
 #include "ColorTable.h"
 #include "Context.h"
diff --git a/Post/PViewDataList.cpp b/Post/PViewDataList.cpp
index fd66dff82df3e3525562633790761d19aa4543cd..1092d8cc3af1310c9b9f42d5441140db82d205b6 100644
--- a/Post/PViewDataList.cpp
+++ b/Post/PViewDataList.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include <algorithm>
 #include "PViewDataList.h"
 #include "GmshMessage.h"
 #include "GmshDefines.h"
diff --git a/Post/PViewVertexArrays.cpp b/Post/PViewVertexArrays.cpp
index d26d909fe412609a6683f1cb9a15fba7ff1ff5fc..72a6885c3ac402161961f4e2749868790d5d4793 100644
--- a/Post/PViewVertexArrays.cpp
+++ b/Post/PViewVertexArrays.cpp
@@ -4,6 +4,7 @@
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
 #include <string.h>
+#include <algorithm>
 #include "GmshMessage.h"
 #include "GmshDefines.h"
 #include "onelab.h"
diff --git a/Post/adaptiveData.cpp b/Post/adaptiveData.cpp
index 6cba227cdec9a8e8f45bfc1ceca49c55fc55565c..1a3fb6e8d5c3e058fa548ad7f164ef25bad1b3c8 100644
--- a/Post/adaptiveData.cpp
+++ b/Post/adaptiveData.cpp
@@ -6,6 +6,7 @@
 #include <math.h>
 #include <list>
 #include <set>
+#include <algorithm>
 #include "adaptiveData.h"
 #include "Plugin.h"
 #include "OS.h"
@@ -71,21 +72,21 @@ static void computeShapeFunctions(fullMatrix<double> *coeffs, fullMatrix<double>
 }
 
 /*! Bergot space is characterised by polynomials
-  \f$ \mathcal B_{ijk} = 
-  \mathcal P_i \left(\frac{\xi }{1-\zeta}\right) 
-  \mathcal P_j \left(\frac{\eta}{1-\zeta}\right) 
-  \left(1-\zeta\right)^{max(i,j)} 
+  \f$ \mathcal B_{ijk} =
+  \mathcal P_i \left(\frac{\xi }{1-\zeta}\right)
+  \mathcal P_j \left(\frac{\eta}{1-\zeta}\right)
+  \left(1-\zeta\right)^{max(i,j)}
   \mathcal P^{2 max(i,j),0}_k \left(2 \zeta -1\right)~|~i,j \leq p, k \leq p - max(i,j) \f$
   and hence by the "monomials"
-  \f$ \mu_{ijk} = 
-  \left(\frac{\xi }{\1-\zeta}\right)^i 
-  \left(\frac{\eta}{\1-\zeta}\right)^j 
+  \f$ \mu_{ijk} =
+  \left(\frac{\xi }{\1-\zeta}\right)^i
+  \left(\frac{\eta}{\1-\zeta}\right)^j
   \left(1-\zeta\right)^{max(i,j)} \zeta^k~|~i,j \leq p~,~k \leq p-max(i,j)
   \f$
 */
-static void computeShapeFunctionsPyramid(fullMatrix<double> *coeffs, 
+static void computeShapeFunctionsPyramid(fullMatrix<double> *coeffs,
                                          fullMatrix<double> *eexps,
-                                         double u, double v, double w, 
+                                         double u, double v, double w,
                                          fullVector<double> *sf,
                                          fullVector<double> *tmp)
 {
@@ -938,67 +939,67 @@ void adaptivePyramid::recurCreate(adaptivePyramid *p, int maxlevel, int level)
   all.push_back(p);
   if(level++ >= maxlevel) return;
 
-  // quad points 
-  adaptiveVertex *p1 = p->p[0]; 
+  // quad points
+  adaptiveVertex *p1 = p->p[0];
   adaptiveVertex *p2 = p->p[1];
   adaptiveVertex *p3 = p->p[2];
   adaptiveVertex *p4 = p->p[3];
 
   // apex
   adaptiveVertex *p5 = p->p[4];
-  
+
   // center of the quad
 
   adaptiveVertex *p1234 = adaptiveVertex::add
     ((p1->x + p2->x + p3->x + p4->x)*0.25,
      (p1->y + p2->y + p3->y + p4->y)*0.25,
      (p1->z + p2->z + p3->z + p4->z)*0.25,allVertices);
-  
+
   // quad edge points
 
   adaptiveVertex *p12 = adaptiveVertex::add
     ((p1->x + p2->x)*0.5,
      (p1->y + p2->y)*0.5,
      (p1->z + p2->z)*0.5,allVertices);
-  
+
   adaptiveVertex *p23 = adaptiveVertex::add
     ((p2->x + p3->x)*0.5,
      (p2->y + p3->y)*0.5,
      (p2->z + p3->z)*0.5,allVertices);
-  
+
   adaptiveVertex *p34 = adaptiveVertex::add
     ((p3->x + p4->x)*0.5,
      (p3->y + p4->y)*0.5,
      (p3->z + p4->z)*0.5,allVertices);
-  
+
   adaptiveVertex *p41 = adaptiveVertex::add
     ((p4->x + p1->x)*0.5,
      (p4->y + p1->y)*0.5,
      (p4->z + p1->z)*0.5,allVertices);
-  
+
   // quad vertex to apex edge points
 
   adaptiveVertex *p15 = adaptiveVertex::add
     ((p1->x + p5->x)*0.5,
      (p1->y + p5->y)*0.5,
      (p1->z + p5->z)*0.5,allVertices);
-  
+
   adaptiveVertex *p25 = adaptiveVertex::add
     ((p2->x + p5->x)*0.5,
      (p2->y + p5->y)*0.5,
      (p2->z + p5->z)*0.5,allVertices);
-  
+
   adaptiveVertex *p35 = adaptiveVertex::add
     ((p3->x + p5->x)*0.5,
      (p3->y + p5->y)*0.5,
      (p3->z + p5->z)*0.5,allVertices);
-  
+
   adaptiveVertex *p45 = adaptiveVertex::add
     ((p4->x + p5->x)*0.5,
      (p4->y + p5->y)*0.5,
      (p4->z + p5->z)*0.5,allVertices);
-  
-  // four base pyramids on the quad base 
+
+  // four base pyramids on the quad base
 
   p->e[0] = new adaptivePyramid(p1, p12, p1234, p41, p15);
   recurCreate(p->e[0], maxlevel, level);
@@ -1171,7 +1172,7 @@ void adaptiveElements<adaptivePyramid>::init(int level)
 
   if(_interpolGeom) delete _interpolGeom;
   _interpolGeom = new fullMatrix<double>(adaptivePyramid::allVertices.size(), numNodes);
-  
+
   fullVector<double> sfv(numVals), *tmpv = 0;
   fullVector<double> sfg(numNodes), *tmpg = 0;
   if(_eexpsVal) tmpv = new fullVector<double>(_eexpsVal->size1());
diff --git a/Post/adaptiveData.h b/Post/adaptiveData.h
index 35fd883bd641934c6f9d35805b0fea671e970cfe..47f29b6483b39c57a39cd7ace3b9b4854ea21c96 100644
--- a/Post/adaptiveData.h
+++ b/Post/adaptiveData.h
@@ -10,6 +10,7 @@
 #include <set>
 #include <vector>
 #include <cstdlib>
+#include <algorithm>
 #include "fullMatrix.h"
 
 class PViewData;
@@ -18,11 +19,11 @@ class GMSH_PostPlugin;
 
 class adaptiveVertex {
  public:
-  float  x, y, z;        //!< parametric coordinates 
+  float  x, y, z;        //!< parametric coordinates
   double X, Y, Z;        //!< cartesian coordinates
   double val,valy,valz;  //!< maximal three values
  public:
-  static adaptiveVertex *add(double x, double y, double z, 
+  static adaptiveVertex *add(double x, double y, double z,
                              std::set<adaptiveVertex> &allVertice);
   bool operator < (const adaptiveVertex &other) const
   {
@@ -49,7 +50,7 @@ class adaptivePoint {
   {
     p[0] = p1;
     e[0] = 0;
-  } 
+  }
   inline double V() const
   {
     return p[0]->val;
@@ -79,7 +80,7 @@ class adaptiveLine {
     p[0] = p1;
     p[1] = p2;
     e[0] = e[1] = 0;
-  } 
+  }
   inline double V() const
   {
     return (p[0]->val + p[1]->val) / 2.;
@@ -137,8 +138,8 @@ class adaptiveQuadrangle {
   static std::set<adaptiveVertex> allVertices;
   static int numNodes, numEdges;
  public:
-  adaptiveQuadrangle(adaptiveVertex *p1, adaptiveVertex *p2, 
-                     adaptiveVertex *p3, adaptiveVertex *p4)    
+  adaptiveQuadrangle(adaptiveVertex *p1, adaptiveVertex *p2,
+                     adaptiveVertex *p3, adaptiveVertex *p4)
     : visible(false)
   {
     p[0] = p1;
@@ -173,7 +174,7 @@ class adaptivePrism {
   static std::set<adaptiveVertex> allVertices;
   static int numNodes, numEdges;
  public:
-  adaptivePrism(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, 
+  adaptivePrism(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3,
                 adaptiveVertex *p4, adaptiveVertex *p5, adaptiveVertex *p6)
     : visible(false)
   {
@@ -214,7 +215,7 @@ class adaptiveTetrahedron {
   static std::set<adaptiveVertex> allVertices;
   static int numNodes, numEdges;
  public:
-  adaptiveTetrahedron(adaptiveVertex *p1, adaptiveVertex *p2, 
+  adaptiveTetrahedron(adaptiveVertex *p1, adaptiveVertex *p2,
                       adaptiveVertex *p3, adaptiveVertex *p4)
     : visible(false)
   {
@@ -251,8 +252,8 @@ class adaptiveHexahedron {
   static std::set<adaptiveVertex> allVertices;
   static int numNodes, numEdges;
  public:
-  adaptiveHexahedron(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, 
-                     adaptiveVertex *p4, adaptiveVertex *p5, adaptiveVertex *p6, 
+  adaptiveHexahedron(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3,
+                     adaptiveVertex *p4, adaptiveVertex *p5, adaptiveVertex *p6,
                      adaptiveVertex *p7, adaptiveVertex *p8)
     : visible(false)
   {
@@ -300,10 +301,10 @@ class adaptivePyramid {
   static std::set<adaptiveVertex> allVertices;
   static int numNodes, numEdges;
  public:
-  adaptivePyramid(adaptiveVertex *p1, 
-                  adaptiveVertex *p2, 
-                  adaptiveVertex *p3, 
-                  adaptiveVertex *p4, 
+  adaptivePyramid(adaptiveVertex *p1,
+                  adaptiveVertex *p2,
+                  adaptiveVertex *p3,
+                  adaptiveVertex *p4,
                   adaptiveVertex *p5)
     : visible(false)
   {
@@ -316,13 +317,13 @@ class adaptivePyramid {
   }
   inline double V() const
   {
-    return (p[0]->val + 
-            p[1]->val + 
-            p[2]->val + 
+    return (p[0]->val +
+            p[1]->val +
+            p[2]->val +
             p[3]->val +
             p[4]->val) / 5.;
   }
-  // barycentric coordinates ? 
+  // barycentric coordinates ?
   inline static void GSF(double u, double v, double w, fullVector<double> &sf)
   {
     double ww = 0.25 / std::max(1e-14,1.-w);
@@ -338,7 +339,7 @@ class adaptivePyramid {
   static void recurError(adaptivePyramid *h, double AVG, double tol);
 };
 
-class PCoords { 
+class PCoords {
  public:
   double c[3];
   PCoords(double x, double y, double z)
@@ -380,7 +381,7 @@ class adaptiveElements {
   // adapt all the T-type elements in the input view and add the
   // refined elements in the output view (we will remove this when we
   // switch to true on-the-fly local refinement in drawPost())
-  void addInView(double tol, int step, PViewData *in, PViewDataList *out, 
+  void addInView(double tol, int step, PViewData *in, PViewDataList *out,
                  GMSH_PostPlugin *plug=0);
 };
 
diff --git a/contrib/Chaco/main/Gmsh_printf.cpp b/contrib/Chaco/main/Gmsh_printf.cpp
index 8f0a42decd616812fbe100b86ebcef9b8ed6c0e6..c0aaa2709c993815995f2721970e32c389f042ea 100644
--- a/contrib/Chaco/main/Gmsh_printf.cpp
+++ b/contrib/Chaco/main/Gmsh_printf.cpp
@@ -6,6 +6,7 @@
 #include <cstdio>
 #include <cstring>
 #include "GmshMessage.h"
+#include <algorithm>
 
 // Overload the printf statements in Chaco to write using Msg::Debug in gmsh
 
diff --git a/contrib/MeshOptimizer/MeshOptObjContrib.cpp b/contrib/MeshOptimizer/MeshOptObjContrib.cpp
index fa244521ec1af9de8004ae2afaaa842cce18e29f..48f1dc0ed8d7374b3c029ed0296eec683c878db7 100644
--- a/contrib/MeshOptimizer/MeshOptObjContrib.cpp
+++ b/contrib/MeshOptimizer/MeshOptObjContrib.cpp
@@ -1,7 +1,7 @@
 // TODO: Copyright
 
 #include "MeshOptObjContrib.h"
-
+#include <algorithm>
 
 const double ObjContrib::BIGVAL = 1.e300;